Skip to content

Commit

Permalink
fails fast when footer size larger than Int.MaxValue
Browse files Browse the repository at this point in the history
  • Loading branch information
ConeyLiu committed Jan 24, 2025
1 parent be5ada2 commit 107cb79
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
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;
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

0 comments on commit 107cb79

Please sign in to comment.