mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2288] [CLOSED] [Other] bound GGUF header reads and report malformed metadata #3964
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#3964
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/2288
Author: @KeyanHu-git
Created: 10/13/2026
Status: ❌ Closed
Base:
main← Head:fix/1919-gguf-header-bounds📝 Commits (5)
762585ftools: validate GGUF headers and tensor extents2309e11tools: derive GGUF extent from header and tensor payloads3732b4emerge current main for GGUF directory validatione90ce85Limit GGUF fix to bounded header parsing and preserve tensor compatibilityd4222d6Preserve valid GGUF alignment and verify parser callers📊 Changes
2 files changed (+235 additions, -27 deletions)
View changed files
📝
tools/gguf_reader.py(+59 -27)➕
tools/test_gguf_reader_malformed.py(+176 -0)📄 Description
Problem and result
A GGUF header with an unknown metadata type or an impossible length can raise
KeyErrororOverflowErrorinside the reader. Setup expects a parsing error, so these files produce a traceback instead of its existing diagnostic naming the broken shard.The reader now checks declared reads and counts against the file and reports parsing failures as
ValueError. Setup can reject the shard through its normal error path, leaving the file intact.Related discussion
The malformed-header cases in #1919. The unknown tensor-size policy established by #92 is preserved. The metadata-only shard case raised in this PR's review is covered by the current upstream setup check and included in validation.
Approach
Strings, scalars, arrays and tensor dimensions share a bounded read operation. Counts are checked before constructing a read or iterating over entries; metadata type IDs are checked before decoding their values. The reader adds the filename once when reporting the error.
Alignment follows the GGUF specification: a positive multiple of 8. Both 24-byte and 64-byte alignment are covered. This corrects the draft's overly strict power-of-two requirement.
The diff is confined to the Python header reader and its regression tests. Tensor geometry support, setup's treatment of readable unknown tensor types, and tensor-payload validation retain their existing behavior.
Validation
Base:
011c9e60(0.2.2 / engine 0.1.47). Final revision:d4222d69. Python 3.12 on macOS and Windows.Passed: all 34 tests on both systems. The checks cover malformed lengths/types/counts, truncated headers, setup's actual
whole_shard()andcheck_shards()error paths, every supported scalar type and its array form, strings and empty arrays, metadata-only files without alignment padding, explicit alignment, and readable unknown tensor types. Existing shard, pack and generated control-vector fixtures also pass.git diff --checkis clean.A read-only comparison of the two installed Coder IQ1_M shards also produced identical metadata, tensor names/shapes/types/offsets, alignment and data start with the original and final readers:
Only headers were read; the model files were unchanged.
Failed: the same tests on unmodified main report 11 errors and 3 failed alignment subtests on both systems. These are the negative controls; the final patch passes them. A check of 24-byte alignment also exposed the earlier draft's compatibility regression, which is corrected in this revision.
Not run: GPU model execution; this change only parses Python-side headers. The malformed files are synthetic fixtures, including the two reproduced in #1919.
Limits
This reader still does not implement nested metadata arrays; it now reports that limitation as a parsing error. It also cannot calculate payload sizes for every future tensor type. This PR keeps those existing support boundaries and does not add a new model-admission policy.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.