Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@AndreCatarino
Copy link

@AndreCatarino AndreCatarino commented Oct 2, 2025

Fixes java.lang.NegativeArraySizeException in SequentialByteArrayReader.getBytes() when processing malformed files with negative size fields.

Solution

  • Added validation for negative count and offset parameters
  • Throws IllegalArgumentException with descriptive message instead of crashing
  • Added comprehensive unit tests for edge cases

Testing

  • Added 3 new test methods in SequentialByteArrayReaderTest
  • Verified fix handles malformed input gracefully

Impact

Prevents crashes when parsing corrupted or malicious files, improving library robustness

- Add validation for negative count parameter in getBytes() methods
- Add validation for negative offset parameter in getBytes(byte[], int, int)
- Throw IllegalArgumentException for invalid parameters instead of allowing NegativeArraySizeException
- Add comprehensive unit tests to verify the fixes

This fixes the exception: java.lang.NegativeArraySizeException in
com.drew.lang.SequentialByteArrayReader.getBytes>com.drew.lang.SequentialReader.getStringValue>com.drew.metadata.photoshop.DuckyReader.extract
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