Skip to content

fix(cpp): validate the aligned value page row count - #1129

Merged
ColinLeeo merged 1 commit into
apache:developfrom
ColinLeeo:aligned-value-page-row-count
Nov 19, 2026
Merged

ColinLeeo merged 1 commit into
apache:developfrom
ColinLeeo:aligned-value-page-row-count

Conversation

@ColinLeeo

Copy link
Copy Markdown
Contributor

The aligned value page starts with a uint32 row count that sizes the not-null bitmap. Validate the count against the page length (64-bit arithmetic so a count near UINT32_MAX cannot wrap), and treat a row index past a non-empty bitmap as corruption in the single-value decode loops. An empty bitmap still means every row is null. Also return the real error code from decode_cur_time_page_data()/decode_cur_value_page_data() instead of collapsing it to 1.

Tests: AlignedValuePageCorruptionTest.{ValidFileReadsEveryRow,OversizedRowCountIsRejected,RowCountThatWrapsBitmapSizeIsRejected}. Full C++ suite passes.

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.

🟡 Changes recommended

The reader checks rounded-up bitmap capacity instead of the declared row count, allowing up to seven extra time rows to be accepted as padding.

1 open issue
What changed in this PR

This PR hardens the C++ aligned-value reader against malformed page row counts and preserves decoding error codes.

Changes:

  • Validates row-count and bitmap sizes using overflow-safe arithmetic.
  • Adds bitmap bounds checks to scalar and batch decoding paths.
  • Adds valid-file and corrupted-row-count regression tests.
File Description
cpp/​test/​reader/​aligned_value_page_corruption_test.cc Adds valid-read, oversized-count, and overflow regression tests.
cpp/​src/​reader/​aligned_chunk_reader.h Adds a shared bitmap bounds-check helper.
cpp/​src/​reader/​aligned_chunk_reader.cc Validates page payloads, checks decoding bounds, and preserves error codes.

Review effort: Balanced

Comment thread cpp/src/reader/aligned_chunk_reader.h Resolved
decode_cur_value_page_data() read the value page's uint32 row count,
sized the not-null bitmap from it, and copied that many bytes out of the
uncompressed page without checking against the page size. The bitmap
index could also run past its end when the time page had more rows.

Reject pages shorter than the count field plus bitmap, compute the bitmap
size in 64-bit arithmetic so a count near UINT32_MAX cannot wrap to zero,
and treat a row beyond the page's declared row count as corruption in the
single-value decode loops (an empty bitmap still means every row is null).
Also return the real error code from
decode_cur_time_page_data()/decode_cur_value_page_data(), which ||
collapsed to 1.
@ColinLeeo
ColinLeeo force-pushed the aligned-value-page-row-count branch from 2a7516d to 15f117c Compare November 19, 2026 07:32
@ColinLeeo
ColinLeeo merged commit 27ecb86 into apache:develop Nov 19, 2026
49 checks passed
ColinLeeo added a commit that referenced this pull request Nov 20, 2026
decode_cur_value_page_data() read the value page's uint32 row count,
sized the not-null bitmap from it, and copied that many bytes out of the
uncompressed page without checking against the page size. The bitmap
index could also run past its end when the time page had more rows.

Reject pages shorter than the count field plus bitmap, compute the bitmap
size in 64-bit arithmetic so a count near UINT32_MAX cannot wrap to zero,
and treat a row beyond the page's declared row count as corruption in the
single-value decode loops (an empty bitmap still means every row is null).
Also return the real error code from
decode_cur_time_page_data()/decode_cur_value_page_data(), which ||
collapsed to 1.

(cherry picked from commit 27ecb86)
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