Repository navigation
Harden GGUF metadata array header parsing - #625
Merged
Merged
Conversation
Validate metadata arrays against remaining encoded bytes and a strict element cap before handing local files to gguf-py or iterating remote header prefixes. Preserve endian handling and continuation-shard metadata while rejecting truncated and deeply nested hostile headers with precise errors. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
Performance Comparison
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens GGUF metadata header parsing by introducing a bounded structural validator that preflights metadata tables (including nested arrays) before constructing the upstream gguf.GGUFReader, and reuses the same validator for remote header-prefix preflight.
Changes:
- Add a shared
_gguf_architecture_from_header(...)validator to bound metadata entry counts, array sizes, and nested array depth. - Pre-validate local GGUF files via
mmapbefore instantiatingGGUFReader, preventing adversarial metadata from triggering expensive upstream parsing/allocation. - Add adversarial tests covering huge counts, truncation, nested arrays, and the safety-cap boundary; update builder preflight to reuse the shared validator.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/mobius/integrations/gguf/_reader.py | Adds a preflight validation pass (via mmap) before constructing GGUFReader. |
| src/mobius/integrations/gguf/_reader_test.py | Adds a regression test ensuring huge metadata arrays are rejected before upstream reader construction. |
| src/mobius/integrations/gguf/_header.py | Introduces shared, bounded GGUF metadata-table structural validation + architecture extraction. |
| src/mobius/integrations/gguf/_builder.py | Replaces the inline header-prefix parser with the shared validator. |
| src/mobius/integrations/gguf/_builder_test.py | Adds tests for the new structural header parser array bounding and truncation behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+43
to
+52
| little_version = struct.unpack_from("<I", data, 4)[0] | ||
| if little_version in {2, 3}: | ||
| byte_order = "<" | ||
| version = little_version | ||
| else: | ||
| version = struct.unpack_from(">I", data, 4)[0] | ||
| if version not in {2, 3}: | ||
| raise ValueError(f"{source!r} uses unsupported GGUF version {little_version}.") | ||
| byte_order = ">" | ||
|
|
justinchuby
added a commit
that referenced
this pull request
Aug 25, 2026
## Summary - fail closed on missing/non-positive/non-divisible BERT and ModernBERT GGUF geometry before graph construction - give non-cached seq2seq encoder masks the encoder sequence length while retaining cross-cache accumulation shapes - prefer modality-specific mmproj projector metadata over the documented global fallback - exclude intentionally skipped tokenizer/RoPE tensors from dense C01 exact closure while retaining unknown-tensor rejection - preserve explicit Falcon-H1 projection-bias enables with the global `attention_bias` compatibility fallback - default missing trailing Cohere `no_rope_layers` entries to RoPE instead of indexing past the schedule ## Audited finding disposition | Finding | Disposition | |---|---| | Encoder metadata/geometry | Retained; missing keys now raise precise `ValueError`, all dimensions must be positive, and hidden size must divide head count | | Seq2seq mask shape | Retained; no-cache uses `encoder_sequence_len`, cross-cache uses `cross_past_sequence_len + encoder_sequence_len` | | mmproj override precedence | Retained; modality key wins, global key remains fallback, missing both fails closed | | Known-skip tensor closure | Retained; known skips are excluded, unknown extras still fail exact closure | | Falcon-H1 bias precedence | Retained; explicit per-projection enables survive and global bias remains backward-compatible | | Cohere bounds | Retained; short schedules no longer raise and unspecified trailing layers use RoPE | ## Validation - final base/head: `0432dab09fe44fc2600f37b2b7d6117a8cbcf619` / `9346006c1549bada7622934c7b74ee573520cdd5` - focused adversarial/positive contract tests: 15 passed - final shared GGUF/config/model/graph suite, including #625–#627 coverage: 3,384 passed, 46 skipped - broad non-integration suite on the immediately preceding rebased main: 7,786 passed, 56 skipped, 1 subtest passed - generated GGUF docs check: passed in shared suite - `lintrunner f --output oneline --all-files`: passed - GPT-5.6 Sol, medium review against final exact base: no significant issues This is one signed-off commit replayed directly on current main. No merge requested; CI is intentionally not awaited. Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Copilot App <[email protected]>
justinchuby
added a commit
that referenced
this pull request
Aug 25, 2026
## Summary - promote Gemma 3, Qwen2-VL, and Qwen2.5-VL text + mmproj graph import - preserve canonical `decoder`, `vision_encoder`, and `embedding` package roles and #625-#630 package/runtime invariants - add exact pinned llama.cpp tensor closures, projector override resolution, Qwen QKV/temporal patch transforms, Gemma projector mapping, and supported quantization paths - bind real pinned Hugging Face processor contracts to float32 graph boundaries, independent image/video streams, batch-major media ordering, and empty-media behavior - keep all downstream multimodal runtime verdicts deferred rather than inferring runtime support from graph construction ## Evidence - real Gemma 3, Qwen2-VL, and Qwen2.5-VL mmproj artifact revisions, sizes, SHA-256 values, qtype inventories, and paired text targets are recorded in the registry and docs - value-based tensor/projector mapping tests cover Gemma 3 and both Qwen variants - synthetic execution covers two-row mixed image/video ordering, text-only and empty-media embedding, Qwen vision execution, decoder prefill, and cached decode - Gemma 3 tests cover the processor-native 256 `<image_soft_token>` placeholders, safe out-of-vocabulary lookup handling, flattened batch offsets, and projector parity - generated generic decoder metadata remains graph-derived ## Runtime waivers Graph import is supported; downstream runtime support remains deferred. Gemma 3 parent processor assets are gated and no ORT GenAI media orchestrator was proven. Qwen runtime still needs proven video alias/timing plumbing and 3D M-RoPE position construction. No audio/codec bundle was promoted without a complete expressible processor/state/runtime contract. ## Residual multimodal blockers - Qwen3-VL: DeepStack decoder-layer injection - Gemma3n: complete MobileNetV5 vision and Conformer audio bundle - Gemma4 audio: remaining `a.pre_encode.*` and Conformer parity - generated-audio sidecars: stateful codec/generation contracts ## Validation - focused GGUF/mmproj/multimodal/package/runtime: `3215 passed` - broad non-integration: `7849 passed, 56 skipped, 1 subtest passed` - initialized repository lint: clean - GPT-5.6 Sol medium architecture review: fixed Gemma 3 boundary-vs-soft-token blocker; no remaining high-confidence findings - GPT-5.6 Sol medium regression review: fixed Qwen evidence references, added vision/prefill/decode execution, and closed the docs artifact census Base: `6ff5f78dafb90609372de023a5ab9d27098dca6d` Head: `ed370d8cecf7adc985d5b372ee050b661f069607` --------- Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Copilot App <[email protected]>
justinchuby
added a commit
that referenced
this pull request
Aug 25, 2026
## Summary - clean up still-valid typing, documentation, test robustness, error-message, maintainability, and performance findings left by the GGUF PR stack - preserve the behavioral fixes merged in #625-#632 - hash reused multi-GB GGUF sources once, at the final pre-publication integrity gate, while retaining cheap identity checks around staging Exact base: `2db9d33debdc254d879a51b14434c9a81c230f4f` Exact head: `4541ed2bc9d2ab4227484510b4a85b2d9113eb25` ## Reconstructed original 17-item low-priority tranche The persisted audit retained only the totals, so this list was reconstructed from the live threads and current source. All but the already-fixed #596 comment are addressed in this PR. | PR | Comment | Disposition | |---|---:|---| | #550 | 3837144656 | Implemented: correct tuple return annotation | | #552 | 3837389183 | Implemented: multichannel waveform shape docs | | #559 | 3837716261 | Implemented: name-based cache assertions | | #573 | 3854308350 | Implemented: one final GGUF hash, with integrity regression coverage | | #574 | 3854345521 | Implemented: `TensorRole \| None` typing | | #574 | 3854345597 | Implemented: removed obsolete verdict filtering | | #577 | 3854472859 | Implemented: documented SSM sequence length | | #578 | 3843112613 | Implemented: documented F64 passthrough | | #579 | 3854518332 | Implemented: generalized fused-projection error | | #580 | 3854576300 | Implemented: removed brittle node counts | | #583 | 3854681386 | Implemented: documented conditional draft outputs | | #587 | 3854816872 | Implemented: corrected MTP output contract docs | | #596 | 3846110059 | Already fixed on base: unambiguous GQA bias comment | | #600 | 3855174281 | Implemented: metadata-count-only MTP error | | #607 | 3855776048 | Implemented: stable route-field assertions | | #607 | 3855776086 | Implemented: public tensor iterator | | #609 | 3856486136 | Implemented: fail-closed LM-head comment | ## Current unresolved-thread disposition This covers all 48 Copilot threads returned by the reproducible #600-#630 query. The one human #623 thread is excluded. | PR | Comment | Current-main disposition and evidence | |---|---:|---| | #600 | 3855174177 | Already fixed by #629: package cycle and reserved-sidecar validation | | #600 | 3855174238 | Already fixed by #629: explicit MTP sidecar naming/loading | | #600 | 3855174281 | Implemented here: error no longer invents an observed block count | | #602 | 3848155961 | Outside exact stack; already fixed: top-level `expert_dtype` is classified before early return | | #602 | 3848155983 | Outside exact stack; still-valid behavioral block-quant validation, unchanged | | #602 | 3848156000 | Outside exact stack; still-valid truncated-read behavioral finding, unchanged | | #602 | 3848156022 | Outside exact stack; still-valid descriptor byte/dtype validation, unchanged | | #602 | 3848156040 | Outside exact stack; still-valid expert-bank payload validation, unchanged | | #603 | 3855249765 | Already fixed by #630: runtime preflight preserves shard sets | | #603 | 3855249840 | Already fixed by #630: success output follows durable runtime publication | | #604 | 3855343082 | Implemented here: graph-only MTP persistence distinguished from runtime rejection | | #604 | 3855343131 | Already fixed by #630: runtime success messages are atomic | | #607 | 3855776001 | Implemented here: missing generation golden skips before provenance read | | #607 | 3855776048 | Implemented here: only stable route fields are asserted | | #607 | 3855776086 | Implemented here: tensor count uses `tensor_items_raw()` | | #608 | 3856079371 | Still-valid behavioral cache-symlink containment finding; unchanged | | #608 | 3856079415 | Still-valid behavioral lowercase-digest validation finding; unchanged | | #609 | 3856486136 | Implemented here: comment matches value-preserving policy | | #610 | 3855541683 | Already fixed by #628: Falcon bias precedence is explicit | | #610 | 3855541761 | Already fixed by #628: CTRL tiny config exercises projection biases | | #611 | 3856595840 | Implemented here: runtime test resolves the distribution providing the module | | #612 | 3855677383 | Already fixed by #625: supported-version endianness detection | | #612 | 3855677427 | Implemented here: shared `INT64_MAX` sentinel | | #612 | 3855677460 | Implemented here: shared PLaMo2 width inference | | #612 | 3855677486 | Implemented here: accepted PLaMo2 activation spellings are explicit | | #613 | 3855845678 | Implemented here: canonical issue URL | | #613 | 3855845757 | Implemented here: Mamba-1 function-registration docs | | #613 | 3855845806 | Implemented here: test expects the canonical issue URL | | #614 | 3855988545 | Implemented here: removed stale Nemotron-H divergence comments | | #614 | 3855988597 | Already fixed by #628: zero-head geometry raises actionable `ValueError` | | #615 | 3856082290 | Already fixed by #626: dense GraniteHybrid bias closure | | #618 | 3856729330 | Implemented here: required routes filter ORT GenAI evidence | | #618 | 3856729409 | Implemented here: env-selected runtime version is authoritative | | #618 | 3856729490 | Stale/N/A: PR-description-only matrix claim; repository workflow claims one pinned version | | #618 | 3856729563 | Implemented here: schema tail restored to normal indentation | | #619 | 3856342484 | Already fixed on base: Kimi Linear uses `/issues/605` | | #619 | 3856342532 | Already fixed by #628: config rejects convolution kernels below 2 | | #619 | 3856342580 | Already fixed by #628: GGUF contract rejects convolution kernels below 2 | | #620 | 3855717041 | Already fixed by #627: tied LM-head-only checkpoints are retained | | #621 | 3856722324 | Already fixed by #628: Kimi-K3 required metadata is complete | | #623 | 3855931210 | N/A to current main: comment belongs to open, unmerged #623 | | #623 | 3855939302 | N/A to current main: comment belongs to open, unmerged #623 | | #623 | 3855939358 | N/A to current main: comment belongs to open, unmerged #623 | | #623 | 3855939394 | N/A to current main: comment belongs to open, unmerged #623 | | #624 | 3856777152 | Implemented here: runtime compatibility reuses the emitted model type | | #625 | 3857049733 | Implemented here: unsupported header reports both endian candidates | | #629 | 3857313182 | Newer post-audit behavioral sidecar-symlink cleanup finding; unchanged | | #629 | 3857313251 | Newer post-audit cross-platform path-safety finding; unchanged | ## Validation - affected GGUF/package/ORT GenAI/model/schema tests: 1,040 passed - broad non-integration suite: 7,851 passed, 56 skipped, 1 subtest passed - generated GGUF docs checks: 7 passed - initialized `lintrunner`; full lint/format passed - GPT-5.6 Sol medium review: one integrity finding fixed; re-review found no significant issues Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Copilot App <[email protected]>
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.
Summary
gguf.GGUFReaderTests
python -m pytest src/mobius/integrations/gguf/_reader_test.py src/mobius/integrations/gguf/_builder_test.py -q --tb=shortpython -m pytest src/mobius/integrations/gguf/_reader_test.py src/mobius/integrations/gguf/_builder_test.py src/mobius/integrations/gguf/_shard_set_test.py src/mobius/integrations/gguf/_preflight_test.py -q --tb=shortpython -m pytest src/mobius/integrations/gguf/_docs_test.py -q --tb=shortpython -m pytest tests/build_graph_test.py tests/cli_test.py src/ -q -k "not phi4mm and not apply_weights_unknown" --tb=short -n autolintrunner f --output oneline src/mobius/integrations/gguf/_header.py src/mobius/integrations/gguf/_reader.py src/mobius/integrations/gguf/_reader_test.py src/mobius/integrations/gguf/_builder.py src/mobius/integrations/gguf/_builder_test.pyFollow-up to review comment #586 (comment).