Skip to content

read stream to end for negative length in writeBinary(InputStream) - #894

Open
Sahana2524 wants to merge 1 commit into
FasterXML:3.xfrom
Sahana2524:writebinary-negative-length
Open

read stream to end for negative length in writeBinary(InputStream)#894
Sahana2524 wants to merge 1 commit into
FasterXML:3.xfrom
Sahana2524:writebinary-negative-length

Conversation

@Sahana2524

Copy link
Copy Markdown
Contributor

Raw exception from writeBinary when stream length is unknown

writeBinary(Base64Variant, InputStream, int) treats a negative dataLength as a real length, but per the JsonGenerator contract a negative value means "length unknown, read to the end of stream", and the JSON backend already handles it that way. The attribute path reaches new byte[dataLength] and the element path a bounded read(..., dataLength), so the call leaves the generator as a raw NegativeArraySizeException / IndexOutOfBoundsException instead of a JacksonException. Reading the stream to the end and then reusing the existing byte[] path (which Stax2 needs for the full-buffer/attribute writes anyway) keeps the output identical to the JSON backend for the same input; non-negative lengths are untouched.

@github-actions

Copy link
Copy Markdown

🧪 Code Coverage Report

Metric Coverage Change
Instructions coverage 74.30% 📈 +0.250%
Branches branches 69.04% 📈 +0.210%

Coverage data generated from JaCoCo test results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant