Repository navigation
der: return an error instead of panicking on truncated binary REAL values - #2483
Open
choksi2212 wants to merge 1 commit into
Open
choksi2212 wants to merge 1 commit into
choksi2212 wants to merge 1 commit into
Conversation
…lues The binary-encoding branch of the REAL (f64) decoder (X.690 section 8.5.7) reads the exponent octets at fixed offsets in the value content without checking that the content is long enough to hold them: the one-octet exponent form indexes bytes[1] and the two-octet exponent form indexes bytes[1] and bytes[2]. A REAL value whose content is the single octet 0x80 therefore reaches bytes[1] on a length-1 slice and panics with 'index out of bounds' instead of returning Err, taking down any caller that decodes f64 values (or structs containing them) from untrusted input. Confirm the content length before reading the exponent octets, in both exponent forms, and return a Real value error otherwise. Fixes RustCrypto#2482 Signed-off-by: choksi2212 <choksi2212@users.noreply.github.com>
This branch has not been deployed
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
The binary-encoding branch of the
REAL(f64) decoder (X.690 section 8.5.7,der/src/asn1/real.rs) reads the exponent octets at fixed offsets in the value content without confirming the content is long enough to hold them: the one-octet exponent form indexesbytes[1], and the two-octet exponent form indexesbytes[1]andbytes[2](GHSA-27m6-7r55-vwr2, #2482).A
REALwhose value content is the single octet0x80therefore reachesbytes[1]on a length-1 slice and panics instead of returningErr:Any caller decoding
f64values (or structs containing them) from untrusted DER can be taken down by a two-byte input (09 01 80).Changes
Tag::Realvalue error the function already uses for other malformed binary REALs. No public API or behavior change for well-formed values.0x80short form,0x81short form with no exponent octets,0x81 00two-octet form missing the second exponent octet).Evidence
masterthe new test fails with the exact panic above (index out of bounds: the len is 1 but the index is 1); with this change all three inputs returnErr.cargo test -p der --features real(lib): 92 passed, 0 failed.cargo test -p der --no-default-features --features real: green.cargo test -p der --features arbitrary,ber,bytes,derive,oid,pem,real,std: green except the pre-existingtests/pem.rs::to_pemCRLF expectation, which fails identically on pristinemasteron a Windows checkout (PEM line endings), unrelated to this change.cargo build -p der --no-default-features(no_std): builds clean.RUSTFLAGS=-Dwarnings cargo clippy -p der --all-features --tests: clean.cargo fmt -p der -- --check: clean.Notes
This is the minimal non-breaking point fix for the published advisory; whether the
REALfeature is removed outright in the next breaking release is a separate call (#2482).