Repository navigation
Do not read CBOR 32-bit lengths >= 2^31 as indefinite length - #912
Open
Dhanu-dynamic wants to merge 1 commit into
Open
Dhanu-dynamic wants to merge 1 commit into
Dhanu-dynamic wants to merge 1 commit into
Conversation
_decodeExplicitLength() returned the 4-byte length form as a signed int, so a definite length of 2^31 or more came back negative, which callers take to mean indefinite length: a definite-length array, map, text, byte string or property name was then read up to a 0xFF break instead. Reject such lengths like the 8-byte form already does.
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.
CBORParser._decodeExplicitLength()returns the 4-byte length form (additional info 26) straight from_decode32Bits(), so a definite length of 2^31 or more wraps to a negativeint. Every read-path caller takes a negative length to mean indefinite length, so the item is read as an indefinite-length one, up to a0xFFbreak.9A FF FF FF FF 01 02 FF(an array of 4294967295 items) reads as[1, 2],7A FF FF FF FF 63 61 62 63 FFas"abc", and the same happens for maps, byte strings and text or binary property names, throughnextToken(),nextFieldName(),nextTextValue(),getText()andgetBinaryValue(). A decoder following RFC 8949 expects 4294967295 items or bytes there and fails, so Jackson accepts a malformed document and returns a structure the bytes do not encode.The 8-byte form (additional info 27) already rejects anything above
Integer.MAX_VALUEwith "Illegal length", and for text and binary values_skipIncomplete()/_skipChunked()already reject these 32-bit lengths through_skipBytes(); only the read path let them through. Integer values have decoded the 4-byte form as unsigned since #30. The check goes in_decodeExplicitLength()so it covers every caller. Jackson's own generator never writes such lengths, since no Java array orStringcan be that long.Explicit32BitLengthTestcovers arrays, maps, text, binary and property names: 5 of its 6 tests fail without the change, and the sixth checks that valid 4-byte lengths still read../mvnw verifypasses on JDK 21. Based on2.21;3.xhas the same_decodeExplicitLength(), so it should merge forward, with the test's package changed totools.jackson. I can add theVERSION-2.xentry once this has a number.