parser lyb BUGFIX bound memory input reads#2538
Conversation
fb87e79 to
b4e6fe6
Compare
|
@michalvasko Updated the existing PR to target Since
I also changed The project builds successfully and all 18 affected test suites pass. Please review the updated version when convenient. |
michalvasko
left a comment
There was a problem hiding this comment.
Seems fine except for one issue, thanks.
c43d095 to
0a695d8
Compare
Require explicit lengths for memory-backed LYB parsing, enforce bounds including zero-length buffers, propagate remaining read failures, validate malformed hashes, and update fuzz and unit coverage.
0a695d8 to
77033de
Compare
|
@michalvasko Removed the unbounded memory-input rejection as requested, preserving compatibility with sysrepo and existing callers. I also updated the regression test to verify that the legacy unbounded LYB path remains supported, while bounded zero-length and truncated inputs still fail safely. Please take another look when convenient. Thanks |
michalvasko
left a comment
There was a problem hiding this comment.
Seems okay, just one minor issue.
| return in->type; | ||
| } | ||
|
|
||
| static LY_ERR |
Summary
Harden memory-backed LYB parsing against out-of-bounds reads caused by truncated or lengthless binary input.
This PR now targets
develand has been adapted to the LYB error handling and bounded-memory parsing support already present there.Problem
LYB is a binary format and may contain embedded NULL bytes. Memory input created with
ly_in_new_memory()has no explicit length, so it cannot safely represent an LYB buffer.Additionally, using
length == 0to mean “unbounded” makes it impossible to safely represent a bounded zero-length buffer. Some cursor calculations could also underflow if the current position moved beyond the input boundary.Malformed LYB schema hashes could reach assertion-only checks, causing the process to abort instead of returning a parser error.
Changes
boundedflag tostruct ly_in.ly_in_read(),ly_in_peek(), andly_in_skip()safely validate bounded reads and cursor movement.ly_in_memory().lyd_parse_data_mem_len()wrapper as bounded.lyd_parse_data_mem_len()length fromsize_ttouint32_t, as requested in review.lyb_read_size()failure.lyd_parse_lybfuzz target to exercise bounded memory parsing directly.Compatibility
Callers must not use the NULL-terminated memory API for binary LYB data:
They should use the existing bounded-memory API instead:
Text-format memory parsing remains unchanged.
Testing
Local verification:
CBOR-specific tests were not available locally because
libcborwas not installed; CI will provide the remaining platform and optional-dependency coverage.