Repository navigation
git Reject negative shape dimensions in NPY format parser - #99812
Merged
alexey-milovidov merged 2 commits intoMar 18, 2026
Merged
Conversation
Contributor
Author
|
Hi @PedroTadim @Algunenano |
Contributor
|
Workflow [PR], commit [6dcfdf7] Summary: ✅ AI ReviewSummaryThis PR fixes a real correctness issue in Missing context
ClickHouse Rules
Final Verdict
|
Contributor
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 87.50% (7/8, 0 noise lines excluded) |
Contributor
Author
|
Hi @PedroTadim @Algunenano |
alexey-milovidov
approved these changes
Mar 18, 2026
alexey-milovidov
left a comment
Member
There was a problem hiding this comment.
I like this change.
But what happens with large non-negative dimensions?
Contributor
Author
|
Thanks @alexey-milovidov and @Algunenano |
Algunenano
added a commit
to Algunenano/ClickHouse
that referenced
this pull request
Mar 24, 2026
Follow-up to ClickHouse#99812 which fixed negative shape dimensions. This addresses the remaining attack surface with large non-negative dimensions: - Validate that the product of all shape dimensions does not overflow `size_t` - Validate that claimed data size matches the actual file size (when known) - Cap per-row memory footprint (data + array offset overhead) to 2 GiB - Cap individual element size to 2 GiB (prevents `|S<huge>` DoS) - Add overflow check in `NumpyDataTypeUnicode` constructor (`size * 4`) - Reject empty shape (prevents OOB access on `shape[0]`) - Add periodic `isCancelled` check in the inner `readValue` loop so `max_execution_time` is respected even for single-row large arrays - Widen shape dimensions from `int` to `size_t` for correctness - Remove dead declarations (`readData`, `readRows`) Closes ClickHouse#99585 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reject negative shape dimensions in NPY format parser.
A maliciously crafted
.npyfile with negative shape dimensions (e.g.shape=(-1,)) causes an infinite loop because the signedintvalue wraps to a huge number when implicitly cast tosize_t. This adds validation that all dimensions are non-negative during header parsing.Closes #99585
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix infinite loop when reading
Npyformat files with negative shape dimensions.Documentation entry for user-facing changes
No documentation changes needed — this is a bug fix for invalid input handling.
Version info
26.3.1.776