[PR #4536] [Engine] gguf_reader: header bounds check cannot wrap on a huge string length #5077

Open
opened 2026-11-07 16:32:32 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4536
Author: @schmittcn
Created: 10/28/2026
Status: 🔄 Open

Base: main ← Head: pr/gguf-cursor-overflow


📝 Commits (1)

  • 92ab610 gguf_reader: the header bounds check cannot wrap (n > size - pos instead of pos + n > size)

📊 Changes

2 files changed (+25 additions, -1 deletions)

View changed files

📝 include/strata/artifact/gguf_reader.hpp (+1 -1)
📝 src/artifact/gguf_reader_test.cpp (+24 -0)

📄 Description

Problem and result

Cursor::need() in include/strata/artifact/gguf_reader.hpp checked pos_ + n > size_. n is a string length read from the file. When a GGUF header gives a length near 2^64, pos_ + n wraps to a small value, the check passes, and str() goes on to build a std::string of that length.

Today that constructor throws std::length_error, which is caught as a bad file, so nothing is read out of bounds. That is luck, not the check. The check is now n > size_ - pos_, which can't wrap (pos_ <= size_ always holds). The same file is refused as "GGUF: unexpected end of file in header", like any other truncated header.

Found by reading the code. Not seen with a real model file.

Validation

Revision: upstream/main at 46c152a1, Linux, g++ (system).

  • Added: a fifth case in src/artifact/gguf_reader_test.cpp, a one-tensor header whose name length is UINT64_MAX - 15.
  • Passed with this change: all 5 cases. Built as g++ -std=c++20 -Iinclude src/artifact/gguf_reader_test.cpp (strata_artifact is header-only, an INTERFACE target).
  • Failed on unmodified main: the new case reports basic_string::_M_create instead of the truncated-header error, which shows the wrap.
  • Passed: cmake -DSTRATA_BUILD_TESTS=ON, then a build of gguf_reader_test, gguf_split_test and strata-gguf, then ctest -R "gguf_(reader|split)_test": 2 of 2 passed.
  • Not run: CUDA, HIP and SYCL engine builds. The change is in the header-only reader and its test.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4536 **Author:** [@schmittcn](https://github.com/schmittcn) **Created:** 10/28/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/gguf-cursor-overflow` --- ### 📝 Commits (1) - [`92ab610`](https://github.com/Niko1221/Strata/commit/92ab610c382925b0d9c6138cac4de57df0cac8f9) gguf_reader: the header bounds check cannot wrap (n > size - pos instead of pos + n > size) ### 📊 Changes **2 files changed** (+25 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/artifact/gguf_reader.hpp` (+1 -1) 📝 `src/artifact/gguf_reader_test.cpp` (+24 -0) </details> ### 📄 Description ## Problem and result `Cursor::need()` in `include/strata/artifact/gguf_reader.hpp` checked `pos_ + n > size_`. `n` is a string length read from the file. When a GGUF header gives a length near 2^64, `pos_ + n` wraps to a small value, the check passes, and `str()` goes on to build a `std::string` of that length. Today that constructor throws `std::length_error`, which is caught as a bad file, so nothing is read out of bounds. That is luck, not the check. The check is now `n > size_ - pos_`, which can't wrap (`pos_ <= size_` always holds). The same file is refused as "GGUF: unexpected end of file in header", like any other truncated header. Found by reading the code. Not seen with a real model file. ## Validation Revision: `upstream/main` at `46c152a1`, Linux, g++ (system). - **Added:** a fifth case in `src/artifact/gguf_reader_test.cpp`, a one-tensor header whose name length is `UINT64_MAX - 15`. - **Passed with this change:** all 5 cases. Built as `g++ -std=c++20 -Iinclude src/artifact/gguf_reader_test.cpp` (`strata_artifact` is header-only, an INTERFACE target). - **Failed on unmodified `main`:** the new case reports `basic_string::_M_create` instead of the truncated-header error, which shows the wrap. - **Passed:** `cmake -DSTRATA_BUILD_TESTS=ON`, then a build of `gguf_reader_test`, `gguf_split_test` and `strata-gguf`, then `ctest -R "gguf_(reader|split)_test"`: 2 of 2 passed. - **Not run:** CUDA, HIP and SYCL engine builds. The change is in the header-only reader and its test. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5077
No description provided.