Skip to content

GH-50971: [C++][Parquet] Fix usage of disparate length types for metadata reading - #50972

Open
pitrou wants to merge 1 commit into
apache:mainfrom
pitrou:pq-uint32
Open

GH-50971: [C++][Parquet] Fix usage of disparate length types for metadata reading#50972
pitrou wants to merge 1 commit into
apache:mainfrom
pitrou:pq-uint32

Conversation

@pitrou

@pitrou pitrou commented Aug 24, 2026

Copy link
Copy Markdown
Member

Rationale for this change

The usage of disparate integer types (int64_t, uint32_t) makes our checks and computations fragile, especially with C++ adding its own integer promotion rules across arithmetic operations.

We have had at least one report (courtesy of Ada Logics and Claude) where a carefully crafted Parquet file can read from an invalid pointer due to arithmetic overflow in the 32-bit domain.

What changes are included in this PR?

Use int64_t throughout most internal APIs and code paths when reading Parquet metadata. Other types such as uint32_t should only be used where necessary when interacting with third-party libraries such as Thrift C++.

Are these changes tested?

By existing tests, and manually using said hand-crafted Parquet file.

Are there any user-facing changes?

Some APIs taking a uint32_t* inout-parameter are deprecated, alternatives taking a int64_t value are available.

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #50971 has been automatically assigned in GitHub to PR creator.

@pitrou
pitrou marked this pull request as ready for review August 24, 2026 16:17
@pitrou
pitrou requested a review from wgtmac as a code owner August 24, 2026 16:17
@github-actions github-actions Bot added the awaiting review Awaiting review label Aug 24, 2026
@pitrou

pitrou commented Aug 24, 2026

Copy link
Copy Markdown
Member Author

@HuaHuaY @adamreeve @wgtmac Do you want to take a look?

@adamreeve adamreeve 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.

This looks like a good improvement to me thanks @pitrou

*len = decryptor->CiphertextLength(static_cast<int32_t>(decrypted_buffer_len));
DeserializeUnencryptedMessage(decrypted_buffer->data(), &decrypted_buffer_len,
int64_t read_bytes = decryptor->CiphertextLength(decrypted_buffer_len);
ARROW_DCHECK_LE(read_bytes, len); // XXX should they be equal?

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.

I think LE is correct here, for consistency with the method documentation and signature. Even if they are usually equal in practice.

Comment on lines +629 to +630
ss << "Cannot decrypt deserialize Thrift message with length " << len
<< ", which overflows uint32\n";

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.

This is used for reading unencrypted messages

Suggested change
ss << "Cannot decrypt deserialize Thrift message with length " << len
<< ", which overflows uint32\n";
ss << "Cannot deserialize Thrift message with length " << len
<< ", which overflows uint32\n";


/// \brief Size of the original thrift encoded metadata footer.
uint32_t size() const;
int64_t size() const;

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.

Should this be considered a breaking change? I think it's probably OK. Any existing consumer code might end up with a narrowing conversion when storing the result of this, or get a different type if they assign to an auto typed variable, but that should work out OK.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I would optimistically say it's ok too. More importantly, I'm not sure anyone but us has a use for this API.

@github-actions github-actions Bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants