MINOR: Reader fails fast when footer size is larger than INT_MAX#3136
Merged
wgtmac merged 1 commit intoapache:masterfrom Mar 5, 2025
Merged
MINOR: Reader fails fast when footer size is larger than INT_MAX#3136wgtmac merged 1 commit intoapache:masterfrom
wgtmac merged 1 commit intoapache:masterfrom
Conversation
Contributor
Author
|
@dylanburati I have tried to support the footer with an unsigned int size in Java implementation. However, due to some limitations, it can not be done. We could write a footer(without encrypted) size larger than Int.MaxValue bytes, while we can not read it due to some limitations in thrift. java.io.IOException: can not read class org.apache.parquet.format.FileMetaData: MaxMessageSize reached
at org.apache.parquet.format.Util.read(Util.java:393)
at org.apache.parquet.format.Util.readFileMetaData(Util.java:156)
at org.apache.parquet.format.converter.ParquetMetadataConverter$3.visit(ParquetMetadataConverter.java:1545)
at org.apache.parquet.format.converter.ParquetMetadataConverter$3.visit(ParquetMetadataConverter.java:1542)
at org.apache.parquet.format.converter.ParquetMetadataConverter$NoFilter.accept(ParquetMetadataConverter.java:1242)
at org.apache.parquet.format.converter.ParquetMetadataConverter.readParquetMetadata(ParquetMetadataConverter.java:1542)
at org.apache.parquet.hadoop.ParquetFileReader.readFooter(ParquetFileReader.java:637)
at org.apache.parquet.hadoop.ParquetFileReader.readFooter(ParquetFileReader.java:571)
Caused by: org.apache.thrift.transport.TTransportException: MaxMessageSize reached
at org.apache.thrift.transport.TEndpointTransport.checkReadBytesAvailable(TEndpointTransport.java:94)
at org.apache.thrift.protocol.TCompactProtocol.checkStringReadLength(TCompactProtocol.java:726)
at org.apache.thrift.protocol.TCompactProtocol.readString(TCompactProtocol.java:675)
at org.apache.parquet.format.InterningProtocol.readString(InterningProtocol.java:269)
at org.apache.parquet.format.KeyValue$KeyValueStandardScheme.read(KeyValue.java:415)
at org.apache.parquet.format.KeyValue$KeyValueStandardScheme.read(KeyValue.java:392)
at org.apache.parquet.format.KeyValue.read(KeyValue.java:327)
at org.apache.parquet.format.FileMetaData$FileMetaDataStandardScheme.read(FileMetaData.java:1338)Since it is a rare condition. Here we just fail fast with an exception. cc @wgtmac |
ConeyLiu
commented
Jan 24, 2025
| LOG.debug("reading footer index at {}", fileMetadataLengthIndex); | ||
| f.seek(fileMetadataLengthIndex); | ||
| int fileMetadataLength = readIntLittleEndian(f); | ||
| long readFileMetadataLength = readIntLittleEndian(f) & 0xFFFFFFFFL; |
Contributor
Author
There was a problem hiding this comment.
read as a unsigned int
wgtmac
approved these changes
Mar 4, 2025
Contributor
Author
|
Thanks @wgtmac |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Rationale for this change
The footer size is limited to unsigned int for some other language implementations, such as Rust. However, it is limited to Int.MaxValue on the Java side due to some limitations(eg, lack of unsigned int supports, the biggest byte array/buffer is limited to Int.MaxValue). So this PR reads the footer size as long and fails fast if it is larger than Int.MaxValue.
What changes are included in this PR?
Are these changes tested?
Existed UTs.
Are there any user-facing changes?
No