Return error instead of asserting on CborInvalidType in advance functions#317
Open
Eun0us wants to merge 1 commit intointel:mainfrom
Open
Return error instead of asserting on CborInvalidType in advance functions#317Eun0us wants to merge 1 commit intointel:mainfrom
Eun0us wants to merge 1 commit intointel:mainfrom
Conversation
Replace cbor_assert(it->type != CborInvalidType) with an explicit error return in cbor_value_advance() and cbor_value_advance_fixed(). When parsing malformed CBOR input, recursive container walking can produce a CborInvalidType state. The assertion causes abort() which is inappropriate for a library that processes untrusted input — callers should receive an error code they can handle gracefully. Found by fuzzing with libFuzzer + AddressSanitizer.
Member
|
Sorry, I don't want this. If you don't trust the input you're parsing, you can check whether the decode was successful in your code with
Unless you can give me an example where this error can happen and there's no way to avoid it in the first place. |
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
Replace
cbor_assert(it->type != CborInvalidType)with an explicit error return(
CborErrorIllegalType) incbor_value_advance()andcbor_value_advance_fixed().Problem
When parsing malformed CBOR input, recursive container walking can produce a
CborInvalidTypestate in the iterator. The current code triggersassert()→abort(),which is inappropriate for a library that processes untrusted input. Callers have no way
to handle the error gracefully.
Crash output:
Fix
Replace the assertion with an early return of
CborErrorIllegalType, allowing callersto detect and handle invalid CBOR data without crashing. The same pattern is applied
to both
cbor_value_advance()andcbor_value_advance_fixed().Testing
Found by fuzzing with libFuzzer + AddressSanitizer on tinycbor bundled with ESP-IDF v5.3.
The fix eliminates the crash on malformed input while preserving correct behavior on valid CBOR data.