Skip to content

GH-51238: [C++][Python][Parquet] Limit schema nesting depth when reading - #51239

Merged
pitrou merged 4 commits into
apache:mainfrom
pitrou:gh51238-pq-nesting-depth
Sep 9, 2026
Merged

GH-51238: [C++][Python][Parquet] Limit schema nesting depth when reading#51239
pitrou merged 4 commits into
apache:mainfrom
pitrou:gh51238-pq-nesting-depth

Conversation

@pitrou

@pitrou pitrou commented Sep 8, 2026

Copy link
Copy Markdown
Member

Rationale for this change

Reconstructing a nested Schema from the Parquet Thrift metadata implies a recursive call that can blow up the stack on pathologically-nested schemas (with thousands of nesting levels or more).

By adding a limit on the schema nesting depth, we turn a stack overflow-induced crash into a regular Parquet error.

Are these changes tested?

By additional unit tests; also privately with a proof-of-concept reproducer that induces a stack overflow exhaustion.

Are there any user-facing changes?

In the unlikely case where a legitimate Parquet file has a deeper schema than the default schema nesting limit in this PR (100), an error will be raised when reading where it used to succeed. The user can bump the limit to circumvent the error.

This PR contains a "Critical Fix". It fixes a crash on a deeply nested Parquet schema that would provoke a stack overflow. It is not an exploitable vulnerability except through denial of service.

Thanks to "1K0CT" for the initial report.

@pitrou pitrou added backport-candidate Critical Fix Bugfixes for security vulnerabilities, crashes, or invalid data. labels Sep 8, 2026
@github-actions github-actions Bot added the awaiting review Awaiting review label Sep 8, 2026
@pitrou
pitrou force-pushed the gh51238-pq-nesting-depth branch from a062326 to 76fba0f Compare September 8, 2026 16:10
Comment on lines +79 to +80
properties.set_footer_read_size(
parquet_scan_options->reader_properties->footer_read_size());

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is a drive-by fix for an unrelated buglet.

@github-actions github-actions Bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Sep 8, 2026
@pitrou

pitrou commented Sep 8, 2026

Copy link
Copy Markdown
Member Author

@github-actions crossbow submit -g cpp

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

Revision: 131c58c

Submitted crossbow builds: ursacomputing/crossbow @ actions-25d1b23663

Task Status
example-cpp-minimal-build-static GitHub Actions
example-cpp-minimal-build-static-system-dependency GitHub Actions
example-cpp-tutorial GitHub Actions
test-build-cpp-fuzz GitHub Actions
test-conda-cpp GitHub Actions
test-conda-cpp-valgrind GitHub Actions
test-debian-13-cpp-amd64 GitHub Actions
test-debian-13-cpp-i386 GitHub Actions
test-debian-experimental-cpp-gcc-15 GitHub Actions
test-fedora-42-cpp GitHub Actions
test-ubuntu-22.04-cpp GitHub Actions
test-ubuntu-22.04-cpp-bundled GitHub Actions
test-ubuntu-22.04-cpp-emscripten GitHub Actions
test-ubuntu-22.04-cpp-no-threading GitHub Actions
test-ubuntu-24.04-cpp GitHub Actions
test-ubuntu-24.04-cpp-bundled-offline GitHub Actions
test-ubuntu-24.04-cpp-gcc-13-bundled GitHub Actions
test-ubuntu-24.04-cpp-gcc-14 GitHub Actions
test-ubuntu-24.04-cpp-minimal-with-formats GitHub Actions
test-ubuntu-24.04-cpp-thread-sanitizer GitHub Actions

@pitrou
pitrou marked this pull request as ready for review September 8, 2026 17:09
@pitrou
pitrou requested a review from wgtmac as a code owner September 8, 2026 17:09
@pitrou

pitrou commented Sep 8, 2026

Copy link
Copy Markdown
Member Author

@wgtmac @adamreeve @HuaHuaY Would you like to review this?

@adamreeve adamreeve left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This all looks good to me thanks @pitrou, I just have one very minor suggestion.

We should also expose this new option in Python, but that could be a follow-up change.

Comment thread cpp/src/parquet/properties.h Outdated
/// The default value is conservative enough for most use cases.
int32_t schema_depth_limit() const { return schema_depth_limit_; }
/// Set the schema nesting depth limit.
void set_schema_depth_limit(int32_t size) { schema_depth_limit_ = size; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It was thinking if we need to reject a negative value here but it seems that it will safely throw later so I'm fine to leave it simple here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we have any conventions regarding the use of int32_t? Could we use uint32_t here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We use signed integers in most public APIs, we should probably not deviate here.

Comment thread cpp/src/parquet/schema.cc
Comment thread cpp/src/parquet/metadata.cc
Comment thread cpp/src/parquet/schema.cc
@pitrou

pitrou commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

We should also expose this new option in Python, but that could be a follow-up change.

I can probably do it in this PR.

@pitrou
pitrou force-pushed the gh51238-pq-nesting-depth branch from 8d4beae to 84d8a65 Compare September 9, 2026 13:27
@pitrou pitrou changed the title GH-51238: [C++][Parquet] Limit schema nesting depth when reading GH-51238: [C++][Python][Parquet] Limit schema nesting depth when reading Sep 9, 2026
@pitrou

pitrou commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

I have addressed all review comments (including the addition on the Python side), do you want to take another look? @adamreeve @wgtmac

@pitrou
pitrou merged commit df40dd4 into apache:main Sep 9, 2026
57 of 60 checks passed
@pitrou pitrou removed the awaiting committer review Awaiting committer review label Sep 9, 2026
@pitrou
pitrou deleted the gh51238-pq-nesting-depth branch September 9, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-candidate Component: C++ Component: Parquet Component: Python Critical Fix Bugfixes for security vulnerabilities, crashes, or invalid data.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants