mapleFU commented on code in PR #39528: URL: https://github.com/apache/arrow/pull/39528#discussion_r1446855104
########## cpp/src/parquet/column_writer_test.cc: ########## @@ -889,6 +891,44 @@ TEST_F(TestByteArrayValuesWriter, CheckDefaultStats) { ASSERT_TRUE(this->metadata_is_stats_set()); } +TEST(TestPageWriter, ThrowsOnPagesTooLarge) { + NodePtr item = schema::Int32("item"); // optional item + NodePtr list(GroupNode::Make("b", Repetition::REPEATED, {item}, ConvertedType::LIST)); + NodePtr bag(GroupNode::Make("bag", Repetition::OPTIONAL, {list})); // optional list + std::vector<NodePtr> fields = {bag}; + NodePtr root = GroupNode::Make("schema", Repetition::REPEATED, fields); + + SchemaDescriptor schema; + schema.Init(root); + + auto sink = CreateOutputStream(); + auto props = WriterProperties::Builder().build(); + + auto metadata = ColumnChunkMetaDataBuilder::Make(props, schema.Column(0)); + std::unique_ptr<PageWriter> pager = + PageWriter::Open(sink, Compression::UNCOMPRESSED, + Codec::UseDefaultCompressionLevel(), metadata.get()); + + uint8_t data; + std::shared_ptr<Buffer> buffer = + std::make_shared<Buffer>(&data, std::numeric_limits<int32_t>::max() + int64_t{1}); + DataPageV1 over_compressed_limit(buffer, /*num_values=*/100, Encoding::BIT_PACKED, + Encoding::BIT_PACKED, Encoding::BIT_PACKED, + /*uncompressed_size=*/100); + EXPECT_THROW(pager->WriteDataPage(over_compressed_limit), ParquetException); Review Comment: Should we uses EXPECT_THAT to gurantee "overflows to INT32_MAX"? ########## cpp/src/parquet/column_writer.cc: ########## @@ -288,6 +291,9 @@ class SerializedPageWriter : public PageWriter { dict_page_header.__set_is_sorted(page.is_sorted()); const uint8_t* output_data_buffer = compressed_data->data(); + if (compressed_data->size() > std::numeric_limits<int32_t>::max()) { + throw ParquetException("Compressed page size overflows to INT32_MAX."); Review Comment: should we note that the page type? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org