diff --git a/presto-hive/src/main/java/com/facebook/presto/hive/parquet/reader/ParquetMetadataReader.java b/presto-hive/src/main/java/com/facebook/presto/hive/parquet/reader/ParquetMetadataReader.java index 54a592d9836f..dd370df26381 100644 --- a/presto-hive/src/main/java/com/facebook/presto/hive/parquet/reader/ParquetMetadataReader.java +++ b/presto-hive/src/main/java/com/facebook/presto/hive/parquet/reader/ParquetMetadataReader.java @@ -37,6 +37,7 @@ import parquet.schema.Type.Repetition; import parquet.schema.Types; +import java.io.BufferedInputStream; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; @@ -85,10 +86,11 @@ public static ParquetMetadata readFooter(FSDataInputStream inputStream, Path fil long metadataLengthIndex = fileSize - PARQUET_METADATA_LENGTH - MAGIC.length; inputStream.seek(metadataLengthIndex); - int metadataLength = readIntLittleEndian(inputStream); + InputStream in = new BufferedInputStream(inputStream, PARQUET_METADATA_LENGTH + MAGIC.length); + int metadataLength = readIntLittleEndian(in); byte[] magic = new byte[MAGIC.length]; - inputStream.readFully(magic); + validateParquet(in.read(magic) == magic.length, "No enough data for MAGIC"); validateParquet(Arrays.equals(MAGIC, magic), "Not valid Parquet file: %s expected magic number: %s got: %s", file, Arrays.toString(MAGIC), Arrays.toString(magic)); long metadataIndex = metadataLengthIndex - metadataLength; @@ -98,7 +100,7 @@ public static ParquetMetadata readFooter(FSDataInputStream inputStream, Path fil file, metadataIndex); inputStream.seek(metadataIndex); - FileMetaData fileMetaData = readFileMetaData(inputStream); + FileMetaData fileMetaData = readFileMetaData(new BufferedInputStream(inputStream, metadataLength)); List schema = fileMetaData.getSchema(); validateParquet(!schema.isEmpty(), "Empty Parquet schema in file: %s", file);