fix: reject/clamp LDF signal bit_width > 64 to prevent UB in decode() - #25
Open
SoundMatt wants to merge 1 commit into
Open
fix: reject/clamp LDF signal bit_width > 64 to prevent UB in decode()#25SoundMatt wants to merge 1 commit into
SoundMatt wants to merge 1 commit into
Conversation
lin::ldf::DB::decode() shifts a uint64_t by up to bit_width - 1 bits (`1ULL << i`) with no upper bound on the LDF-declared bit_width. LDF signals with bit_width > 64 (unconstrained int, no range check in parse_signals()) trigger a shift-by->=64, which is undefined behavior and aborts under UBSan. Reaching the actual UB requires decode()'s data argument to exceed 8 bytes, which is a normal, unbounded std::vector<uint8_t>& — a malformed or crafted .ldf file can therefore crash any process that parses it and later decodes an oversized frame against it. Fixes: - parse_signals() now rejects (skips) any signal whose parsed bit_width falls outside [1, 64], consistent with how the parser already skips other malformed signal lines rather than storing bad data. - decode() additionally clamps its own loop bound to [0, 64] as defense in depth, since DB's storage members are public and a Signal can be constructed directly by a caller that bypasses the text parser entirely. Closes #18 Signed-off-by: Matt <47545907+SoundMatt@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
lin::ldf::DB::decode()has an unclamped bit-shift for LDF signals withbit_width > 64— undefined behavior (aborts under UBSan), reachable via amalformed/crafted
.ldffile plus adecode()call against a >8-bytebuffer.
parse_signals()now rejects (skips) any signal whose declaredbit_widthis outside[1, 64].decode()additionally clamps its own loop bound to[0, 64]as defensein depth, since
DB's storage is public and aSignalcan beconstructed directly without going through the text parser.
Closes #18
Test plan
ctest— 174/174 pass (3 new regression tests: parser-level rejectionof
bit_width128 and 0, plus adecode()-level defense-in-depthtest that directly constructs a
DB/Signalwithbit_width = 200bypassing the parser, and confirms no UB/crash and a correctly
clamped result)
relay conform --strict/relay interop --protocol LIN— both PASS