fix: validate RLBE decoder run lengths - #913
Open
ColinLeeo wants to merge 3 commits into
Open
Conversation
ColinLeeo
force-pushed
the
fix/rlbe-decoder-validation
branch
from
August 20, 2026 06:23
b30daa6 to
b8a2a83
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens RLBE decoding in both the Java and C++ implementations to better defend against malformed/corrupted encoded data (preventing out-of-bounds access, overflow, and invalid decoded output) and adds regression coverage for key failure cases.
Changes:
- Java: add RLBE block size validation and stricter Fibonacci/run-length validation with
TsFileDecodingException. - C++: tighten RLBE block size validation and add Fibonacci bounds/overflow + remaining-length checks returning
E_TSFILE_CORRUPTED. - Tests: add Java and C++ regression tests for zero block size and run length exceeding the declared block size.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| java/tsfile/src/test/java/org/apache/tsfile/encoding/decoder/RLBEDecoderTest.java | Adds Java regression tests for invalid RLBE block size and excessive run length. |
| java/tsfile/src/main/java/org/apache/tsfile/encoding/decoder/LongRLBEDecoder.java | Adds block size validation and stronger Fibonacci/run-length validation for long RLBE decoding. |
| java/tsfile/src/main/java/org/apache/tsfile/encoding/decoder/IntRLBEDecoder.java | Adds block size validation and stronger Fibonacci/run-length validation for int RLBE decoding. |
| cpp/test/encoding/rlbe_codec_test.cc | Adds C++ regression tests for invalid RLBE block size and excessive run length. |
| cpp/src/encoding/rlbe_decoder.h | Tightens C++ RLBE decoding validation (block size, Fibonacci bounds/overflow, remaining-length checks). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
103
to
+107
| int j = 1; | ||
| while (true) { | ||
| if (j >= fibonacci.length) { | ||
| throw new TsFileDecodingException("Invalid RLBE Fibonacci run length"); | ||
| } |
Comment on lines
104
to
+108
| int j = 1; | ||
| while (true) { | ||
| if (j >= fibonacci.length) { | ||
| throw new TsFileDecodingException("Invalid RLBE Fibonacci run length"); | ||
| } |
Comment on lines
+148
to
+152
| int j = 1; | ||
| while (true) { | ||
| if (j >= static_cast<int>(sizeof(fibonacci_) / | ||
| sizeof(fibonacci_[0]))) { | ||
| return common::E_TSFILE_CORRUPTED; |
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
Fix RLBE decoder validation in both Java and C++ to prevent malformed input from causing out-of-bounds access, integer overflow, excessive reads, or invalid decoded output.
Changes
TsFileDecodingExceptionE_TSFILE_CORRUPTEDMotivation
Previously, the RLBE decoders trusted the encoded run length without checking it against the declared block size. A malformed or corrupted TsFile could therefore cause array index errors, buffer underflow, integer overflow, or the decoding of more values than declared.
Testing
RLBEDecoderTest: 10 tests passed.rlbe_codec_test.cc.git diff --checkpassed.