Skip to content

GH-49959: [C++][Parquet] Avoid unbounded temp alloc in BYTE_STREAM_SPLIT decoder#49960

Merged
pitrou merged 1 commit into
apache:mainfrom
pitrou:gh49959-bss-temp-mem-alloc
May 12, 2026
Merged

GH-49959: [C++][Parquet] Avoid unbounded temp alloc in BYTE_STREAM_SPLIT decoder#49960
pitrou merged 1 commit into
apache:mainfrom
pitrou:gh49959-bss-temp-mem-alloc

Conversation

@pitrou

@pitrou pitrou commented May 11, 2026

Copy link
Copy Markdown
Member

Rationale for this change

The BYTE_STREAM_SPLIT encoder and decoder allocate a SmallVector to hold the addresses of the different streams. While this is valid for small number of streams (which is most or all legitimate use cases), very large numbers of streams (e.g. FLBA(100000000)) can trigger a huge temporary memory allocation.

This issue was found by OSS-Fuzz: https://issues.oss-fuzz.com/issues/511575321

What changes are included in this PR?

  1. When the width of the BYTE_STREAM_SPLIT-encoded type is larger than a predefined constant, switch to a slower implementation that doesn't need any temporary allocation
  2. When encoding or decoding 0 values, avoid some pointless setup work
  3. Add tests for the two conditions above

Are these changes tested?

Yes, by additional unit tests and by additional fuzz regression file.

Are there any user-facing changes?

@pitrou

pitrou commented May 11, 2026

Copy link
Copy Markdown
Member Author

@github-actions crossbow submit -g cpp

@github-actions

Copy link
Copy Markdown

Revision: 14e16db

Submitted crossbow builds: ursacomputing/crossbow @ actions-51f44d0cee

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 May 11, 2026 14:52
@pitrou
pitrou requested a review from wgtmac as a code owner May 11, 2026 14:52
@pitrou
pitrou force-pushed the gh49959-bss-temp-mem-alloc branch from 14e16db to 9a3d8cc Compare May 12, 2026 07:03
Comment thread cpp/src/arrow/util/byte_stream_split_internal.h
@github-actions github-actions Bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels May 12, 2026
@pitrou
pitrou force-pushed the gh49959-bss-temp-mem-alloc branch from 9a3d8cc to 982682b Compare May 12, 2026 09:21
@pitrou
pitrou merged commit a3f3d8b into apache:main May 12, 2026
54 of 55 checks passed
@pitrou pitrou removed the awaiting committer review Awaiting committer review label May 12, 2026
@pitrou
pitrou deleted the gh49959-bss-temp-mem-alloc branch May 12, 2026 10:09
@pitrou

pitrou commented May 12, 2026

Copy link
Copy Markdown
Member Author

Thanks for the review @wgtmac !

@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 3 benchmarking runs that have been run so far on merge-commit a3f3d8b.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 2 possible false positives for unstable benchmarks that are known to sometimes produce them.

@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 3 benchmarking runs that have been run so far on merge-commit a3f3d8b.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details.

Mottl pushed a commit to Mottl/arrow that referenced this pull request May 26, 2026
…EAM_SPLIT decoder (apache#49960)

### Rationale for this change

The BYTE_STREAM_SPLIT encoder and decoder allocate a `SmallVector` to hold the addresses of the different streams. While this is valid for small number of streams (which is most or all legitimate use cases), very large numbers of streams (e.g. FLBA(100000000)) can trigger a huge temporary memory allocation.

This issue was found by OSS-Fuzz: https://issues.oss-fuzz.com/issues/511575321

### What changes are included in this PR?

1. When the width of the BYTE_STREAM_SPLIT-encoded type is larger than a predefined constant, switch to a slower implementation that doesn't need any temporary allocation
2. When encoding or decoding 0 values, avoid some pointless setup work
3. Add tests for the two conditions above

### Are these changes tested?

Yes, by additional unit tests and by additional fuzz regression file.

### Are there any user-facing changes?

* GitHub Issue: apache#49959

Authored-by: Antoine Pitrou <antoine@python.org>
Signed-off-by: Antoine Pitrou <antoine@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants