Skip to content

[Fix] Validate ByteBuffer payload lengths before allocation - #1008

Merged
jt2594838 merged 1 commit into
apache:developfrom
Caideyipi:fix-rwio-payload-length-validation
Oct 14, 2026
Merged

jt2594838 merged 1 commit into
apache:developfrom
Caideyipi:fix-rwio-payload-length-validation

Conversation

@Caideyipi

Copy link
Copy Markdown
Contributor

A malformed length prefix can make ReadWriteIOUtils allocate an oversized byte array before ByteBuffer reports underflow. Move the reusable bounds checks from apache/iotdb#18815 into the shared TsFile readers so oversized lengths throw BufferUnderflowException before allocation.

Route fixed-width, varint, and explicit-length string reads and self-described byte arrays through checked readBytes, which also protects readBinary. Bound Map and LinkedHashMap entry counts by the minimum two string length prefixes per entry, while preserving the null-map sentinel.

Add 15 regression tests for oversized lengths, truncated fixed-width prefixes, buffer limits and offsets, direct and read-only buffers, null/empty/Unicode values, map order, and successful buffer position advancement.

Validation:

  • All 55 tests passed across ReadWriteIOUtilsTest, ReadWriteForEncodingUtilsTest, ReadWriteStreamUtilsTest, ReadWriteToBytesUtilsTest, TabletTest, MeasurementSchemaSerializeTest, and TsBlockSerdeTest.
  • Spotless and Checkstyle passed as part of the Maven test lifecycle.
mvn -o -P with-java -pl java/tsfile -am test -Dtest=ReadWriteIOUtilsTest,ReadWriteForEncodingUtilsTest,ReadWriteStreamUtilsTest,ReadWriteToBytesUtilsTest,TabletTest,MeasurementSchemaSerializeTest,TsBlockSerdeTest -Dsurefire.failIfNoSpecifiedTests=false

@jt2594838
jt2594838 merged commit 6434ef4 into apache:develop Oct 14, 2026
19 checks passed
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.

2 participants