fix: clamp LDF signal bit_width to [1, 64] to eliminate UB in decode() - #28
Open
SoundMatt wants to merge 1 commit into
Open
fix: clamp LDF signal bit_width to [1, 64] to eliminate UB in decode()#28SoundMatt wants to merge 1 commit into
SoundMatt wants to merge 1 commit into
Conversation
Signal::bit_width was an unconstrained int parsed straight from LDF text with no upper bound. DB::decode() then looped `1ULL << i` up to bit_width, which is undefined behavior (and a UBSan abort) for any bit_width >= 64. A crafted or malformed .ldf file with an out-of-range signal width could reach this UB via the public decode() API given a data buffer longer than 8 bytes. parse_signals() now rejects bit_width values outside [1, 64] at parse time (leaving the signal at its safe zero default), and decode() itself clamps the loop bound to 64 as defense in depth, in case a DB is ever constructed with an out-of-range Signal by some other path. 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.
Problem
Signal::bit_widthwas an unconstrainedintparsed directly from LDFtext with no upper-bound check.
DB::decode()then loopedval |= (uint64_t)1 << iup tobit_width, which is undefined behavior(and a UBSan abort under this repo's own
sanitizers/fusa-asil-bgates) for any
bit_width >= 64.An LDF is an external, semi-trusted config file, so a crafted or
malformed one with an out-of-range signal width could reach this UB via
the public
decode()API given a data buffer longer than 8 bytes — astraightforward DoS via untrusted input.
Fix
parse_signals()now rejectsbit_widthvalues outside[1, 64]atparse time, leaving the signal's
bit_widthat its safe zero defaultrather than an unclamped out-of-range value.
decode()itself also clamps the loop bound to 64 as defense indepth, in case a
DBis ever populated with an out-of-rangeSignalby some path other than
parse().Testing
rejection and that
decode()does not throw/abort even with a databuffer sized to reach every byte the old unclamped width would have
touched.
decode()layer.ctest(178/178 passing).ctest(178/178 passing, no aborts).Closes #18