Skip to content

GH-46724: [C++][Parquet] OSSFuzz: Prevent from Bad-cast in handling statistics #46725

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

Open
wants to merge 1 commit into
base: main
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
10 changes: 8 additions & 2 deletions cpp/src/parquet/metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,13 @@ static std::shared_ptr<geospatial::GeoStatistics> MakeColumnGeometryStats(

std::shared_ptr<Statistics> MakeColumnStats(const format::ColumnMetaData& meta_data,
const ColumnDescriptor* descr) {
switch (static_cast<Type::type>(meta_data.type)) {
auto metadata_type = static_cast<Type::type>(meta_data.type);
Copy link
Member

Choose a reason for hiding this comment

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

Why not use LoadEnumSafe?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know (

if (descr->physical_type() != metadata_type) {
throw ParquetException(
"ColumnMetaData type does not match ColumnDescriptor physical type: " +
TypeToString(metadata_type) + " vs. " + TypeToString(descr->physical_type()));
}
switch (metadata_type) {
case Type::BOOLEAN:
return MakeTypedColumnStats<BooleanType>(meta_data, descr);
case Type::INT32:
Expand Down Expand Up @@ -1541,7 +1547,7 @@ bool ApplicationVersion::VersionEq(const ApplicationVersion& other_version) cons
// parquet-mr/parquet-column/src/main/java/org/apache/parquet/CorruptStatistics.java
// PARQUET-686 has more discussion on statistics
bool ApplicationVersion::HasCorrectStatistics(Type::type col_type,
EncodedStatistics& statistics,
const EncodedStatistics& statistics,
SortOrder::type sort_order) const {
// parquet-cpp version 1.3.0 and parquet-mr 1.10.0 onwards stats are computed
// correctly for all types
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/parquet/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class PARQUET_EXPORT ApplicationVersion {
bool VersionEq(const ApplicationVersion& other_version) const;

// Checks if the Version has the correct statistics for a given column
bool HasCorrectStatistics(Type::type primitive, EncodedStatistics& statistics,
bool HasCorrectStatistics(Type::type primitive, const EncodedStatistics& statistics,
SortOrder::type sort_order = SortOrder::SIGNED) const;
};

Expand Down
Loading