Raise a better exception when reading a length-0 Parquet file

This commit is contained in:
Wes McKinney committed 2019-05-20 16:30:49 -05:00
1 parent dff9e30297
commit 3b3f47523e
2 files changed
+22 -2

No files matched your search

+7 -2
View File
@@ -161,8 +161,13 @@ class SerializedFile : public ParquetFileReader::Contents {
void ParseMetaData() {
int64_t file_size = source_->Size();
if (file_size < FOOTER_SIZE) {
throw ParquetException("Corrupted file, smaller than file footer");
if (file_size == 0) {
throw ParquetException("Invalid Parquet file size is 0 bytes");
} else if (file_size < FOOTER_SIZE) {
std::stringstream ss;
ss << "Invalid Parquet file size is " << file_size
<< " bytes, smaller than standard file footer";
throw ParquetException(ss.str());
}
uint8_t footer_buffer[DEFAULT_FOOTER_READ_SIZE];
+15
View File
@@ -2651,3 +2651,18 @@ def test_dataset_metadata(tempdir):
assert d.pop('serialized_size') == 0
assert d2.pop('serialized_size') > 0
assert d == d2
def test_parquet_file_too_small(tempdir):
path = str(tempdir / "test.parquet")
with pytest.raises(pa.ArrowIOError,
match='size is 0 bytes'):
with open(path, 'wb') as f:
pass
pq.read_table(path)
with pytest.raises(pa.ArrowIOError,
match='size is 4 bytes'):
with open(path, 'wb') as f:
f.write(b'ffff')
pq.read_table(path)