Repository navigation
fix(asn1parser): format the signed minimum exactly - #614
Merged
mouse07410 merged 1 commit intoNov 18, 2026
Merged
Conversation
asn1p_itoa_s() handled values that do not fit long by negating them to obtain the magnitude, which overflows for ASN_INTEGER_MIN. It worked around that with two hard-coded strings, and both were wrong: the 128-bit literal ended in ...729 instead of ...728 and the 64-bit one in ...809 instead of ...808. The branch also returned 41 and 21, counting the terminating NUL, although the header promises the length of the numeric value (40 and 20). Compute the magnitude in asn1c_uinteger_t instead: converting to unsigned and subtracting from zero is defined for every value and yields |v| even for the minimum. Split that magnitude with unsigned arithmetic and keep the existing nine-digit padding and the long fast path. The width-specific literals, the negation and the switch are gone, so the result no longer depends on long or on the configured width. Extend the libasn1parser unit test with exact strings, return lengths and the buffer-size contract, including both limits and their neighbours. The boundary script now also checks that -E -F prints the exact minimum, since the old value could not be re-parsed.
1 of 3 tasks
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.
asn1p_itoa_s() handled values that do not fit long by negating them to obtain the magnitude, which overflows for ASN_INTEGER_MIN. It worked around that with two hard-coded strings, and both were wrong: the 128-bit literal ended in ...729 instead of ...728 and the 64-bit one in ...809 instead of ...808. The branch also returned 41 and 21, counting the terminating NUL, although the header promises the length of the numeric value (40 and 20).
Compute the magnitude in asn1c_uinteger_t instead: converting to unsigned and subtracting from zero is defined for every value and yields |v| even for the minimum. Split that magnitude with unsigned arithmetic and keep the existing nine-digit padding and the long fast path. The width-specific literals, the negation and the switch are gone, so the result no longer depends on long or on the configured width.
Extend the libasn1parser unit test with exact strings, return lengths and the buffer-size contract, including both limits and their neighbors. The boundary script now also checks that -E -F prints the exact minimum, since the old value could not be re-parsed.
Fixes #613