Skip to content
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

[MINOR]: Fail fast when footer size larger than Int.MaxValue #3136

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,12 @@ private static final ParquetMetadata readFooter(
long fileMetadataLengthIndex = fileLen - magic.length - FOOTER_LENGTH_SIZE;
LOG.debug("reading footer index at {}", fileMetadataLengthIndex);
f.seek(fileMetadataLengthIndex);
int fileMetadataLength = readIntLittleEndian(f);
long readFileMetadataLength = readIntLittleEndian(f) & 0xFFFFFFFFL;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

read as a unsigned int

if (readFileMetadataLength > Integer.MAX_VALUE) {
throw new RuntimeException("footer is too large: " + readFileMetadataLength + "to be read");
}
int fileMetadataLength = (int) readFileMetadataLength;

f.readFully(magic);

boolean encryptedFooterMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1915,7 +1915,7 @@ private static void serializeFooter(
out.write(serializedFooter);
out.write(signature);
LOG.debug("{}: footer and signature length = {}", out.getPos(), (out.getPos() - footerIndex));
BytesUtils.writeIntLittleEndian(out, toIntWithCheck(out.getPos() - footerIndex, "page"));
BytesUtils.writeIntLittleEndian(out, toIntWithCheck(out.getPos() - footerIndex, "footer"));
out.write(MAGIC);
return;
}
Expand All @@ -1925,7 +1925,7 @@ private static void serializeFooter(
writeFileCryptoMetaData(fileEncryptor.getFileCryptoMetaData(), out);
byte[] footerAAD = AesCipher.createFooterAAD(fileEncryptor.getFileAAD());
writeFileMetaData(parquetMetadata, out, fileEncryptor.getFooterEncryptor(), footerAAD);
int combinedMetaDataLength = toIntWithCheck(out.getPos() - cryptoFooterIndex, "page");
int combinedMetaDataLength = toIntWithCheck(out.getPos() - cryptoFooterIndex, "footer");
LOG.debug("{}: crypto metadata and footer length = {}", out.getPos(), combinedMetaDataLength);
BytesUtils.writeIntLittleEndian(out, combinedMetaDataLength);
out.write(EFMAGIC);
Expand Down
Loading