Skip to content

fix: validate RLBE decoder run lengths - #913

Open
ColinLeeo wants to merge 3 commits into
apache:developfrom
ColinLeeo:fix/rlbe-decoder-validation
Open

fix: validate RLBE decoder run lengths#913
ColinLeeo wants to merge 3 commits into
apache:developfrom
ColinLeeo:fix/rlbe-decoder-validation

Conversation

@ColinLeeo

@ColinLeeo ColinLeeo commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

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

  • Validate that the RLBE block size is within the supported range.
  • Reject Fibonacci codes that exceed the decoder buffer bounds.
  • Detect Fibonacci value overflow.
  • Ensure the decoded run length does not exceed the remaining values in the current block.
  • Return an appropriate decoding error for malformed data:
    • Java: TsFileDecodingException
    • C++: E_TSFILE_CORRUPTED
  • Add regression tests for:
    • An invalid zero block size.
    • A run length exceeding the declared block size.

Motivation

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

  • Java RLBEDecoderTest: 10 tests passed.
  • Added equivalent C++ regression tests to rlbe_codec_test.cc.
  • git diff --check passed.

@ColinLeeo
ColinLeeo force-pushed the fix/rlbe-decoder-validation branch from b30daa6 to b8a2a83 Compare August 20, 2026 06:23
@ColinLeeo
ColinLeeo requested review from HTHou and a lite review from Copilot August 20, 2026 09:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 thread cpp/src/encoding/rlbe_decoder.h Outdated
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;
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