Several functions in cstruct may use wrong data, leading to unexpected exceptions and return corrupted data.
Cstruct.filter_map writes retained bytes at their original input positions, producing corrupted output when earlier bytes are dropped.Cstruct.tail ~rev:true removes two bytes instead of one and raises an exception for single-byte views.Cstruct.cuts ~rev:true may compare input against the wrong data, split at incorrect positions, and construct results using offsets outside the requested view.Cstruct.find and Cstruct.find_sub ~rev:true may return slices from the wrong location when operating on non-zero-offset views.These are a set of logical indexing and bounds-calculation errors (CWE-682), and not direct memory-safety vulnerabilities. However, affected operations may return corrupted data, raise an unexpected exception, split input incorrectly, or return bytes outside the requested Cstruct view but still within its backing buffer.
In security-sensitive parsers, this could cause validation bypasses, denial of service, or unintended disclosure of adjacent buffer contents.
Users unable to upgrade cstruct should backport the corresponding source changes. There is no configuration-based mitigation since these are buggy library calls.
Discovered via Scrutineer and Deepseek GLM-5.3 Flash running locally.
{
"cwe": [
"CWE-682"
],
"human_link": "https://github.com/ocaml/security-advisories/tree/main/advisories/2026/OSEC-2026-20.md",
"osv": "https://github.com/ocaml/security-advisories/tree/generated-osv/2026/OSEC-2026-20.json"
}