-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-38326: [C++][Parquet] check the decompressed page size same as size in page header #38327
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -879,6 +879,48 @@ TEST_F(TestPageSerde, DataPageV2CrcCheckNonExistent) { | |
/* write_data_page_v2 */ true); | ||
} | ||
|
||
TEST_F(TestPageSerde, BadCompressedPageSize) { | ||
// GH-38326: an exception should be raised if a compressed data page | ||
// decompresses to a smaller size than declared in the data page header. | ||
auto codec_types = GetSupportedCodecTypes(); | ||
mapleFU marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const int data_page_bytes = 8192; | ||
const int32_t num_rows = 32; // dummy value | ||
data_page_header_.num_values = num_rows; | ||
std::vector<uint8_t> faux_data; | ||
// A well-compressible piece of data | ||
faux_data.resize(data_page_bytes, 1); | ||
for (auto codec_type : codec_types) { | ||
mapleFU marked this conversation as resolved.
Show resolved
Hide resolved
|
||
auto codec = GetCodec(codec_type); | ||
std::vector<uint8_t> buffer; | ||
const uint8_t* data = faux_data.data(); | ||
int data_size = static_cast<int>(faux_data.size()); | ||
|
||
int64_t max_compressed_size = codec->MaxCompressedLen(data_size, data); | ||
buffer.resize(max_compressed_size); | ||
|
||
int64_t actual_size; | ||
ASSERT_OK_AND_ASSIGN( | ||
actual_size, codec->Compress(data_size, data, max_compressed_size, &buffer[0])); | ||
// Write a data page header declaring a larger decompressed size than actual | ||
ASSERT_NO_FATAL_FAILURE(WriteDataPageHeader(data_page_bytes, data_size + 1, | ||
mapleFU marked this conversation as resolved.
Show resolved
Hide resolved
|
||
static_cast<int32_t>(actual_size))); | ||
ASSERT_OK(out_stream_->Write(buffer.data(), actual_size)); | ||
InitSerializedPageReader(num_rows, codec_type); | ||
|
||
EXPECT_THROW_THAT( | ||
[&]() { page_reader_->NextPage(); }, ParquetException, | ||
::testing::AnyOf( | ||
::testing::Property( | ||
&ParquetException::what, | ||
::testing::HasSubstr("Page didn't decompress to expected size")), | ||
// Some decompressor, like zstd, might be able to detect the error | ||
// before checking the page size. | ||
Comment on lines
+916
to
+917
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ZSTD would throw an |
||
::testing::Property(&ParquetException::what, | ||
::testing::HasSubstr("IOError")))); | ||
ResetStream(); | ||
} | ||
} | ||
|
||
// ---------------------------------------------------------------------- | ||
// File structure tests | ||
|
||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The requirement is that uncompressed_len from the page header is something that we can always trust.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen the arrow-rs implemention, it check the size here. The main problem is that the size is not exact, the decoder will have bad tail buffer, like getting
0
in that multi-gzip file.