Skip to content

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

Open
ColinLeeo wants to merge 1 commit into
apache:developfrom
ColinLeeo:aligned-value-page-row-count
Open

ColinLeeo wants to merge 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.

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 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(), which ||
collapsed to 1.

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 on lines +256 to +258
return !value_page_col_notnull_bitmap_.empty() &&
static_cast<size_t>(row / 8) >=
value_page_col_notnull_bitmap_.size();
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