Repository navigation
der: reject malformed binary REAL values instead of panicking - #2501
Merged
tarcieri merged 1 commit intoNov 1, 2026
Merged
Conversation
The binary-encoding branch of the f64 decoder still trusts the rest of the value content after RustCrypto#2483: - a mantissa longer than eight octets underflows `7 - pos` and indexes `n_bytes` out of bounds, which panics in debug and release builds; - a zero mantissa makes encode_f64() compute `mantissa - 1`, which panics in debug builds and returns NaN in release builds; - an exponent outside the range of an f64 overflows the i16 addition in encode_f64(), which panics in debug builds and returns an unrelated value in release builds (exponent 0x7fff decodes to 0.5). Return a value error for each of these, as RustCrypto#2483 does for truncated content, and add a test with these inputs. Assisted-by: Claude Code:claude-opus-5-5
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.
Follow-up to #2482 / #2483. The binary-encoding branch of the
f64decoder still trusts the rest of the value content after the exponent:realfeature)09 0b 80 00 01 01 01 01 01 01 01 01 0109 03 80 00 00mantissa - 1)Ok(NaN)09 04 81 7f ff 01+ 1023inencode_f64)Ok(0.5)Same results on
master(47e6ffd) and onder0.8.3 from crates.io.This returns
Tag::Real.value_error()for a mantissa longer than eight octets, a mantissa that is zero after the scaling shift (X.690 8.5.2: zero has no contents octets), and an exponent outside -1023..=1023. A new test,decode_malformed_binary_encoding_is_an_error, covers these inputs. With any one of the three checks removed, the test fails.cargo test -p der --features real(120 passed),cargo clippy -p der --features real --all-targets -- -D warningsandcargo fmt --checkpass.This change was prepared with AI assistance (Claude Code), which also ran the checks above.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Sjtw7YxFWFKBH5rRZfwi9T