Repository navigation
Conversation
The pinned stable-diffusion.cpp narrows the remaining span to int before scanning a pickle operand for its newline, and read_torch_legacy_file passes the rest of the whole checkpoint, so a valid legacy checkpoint above 2 GiB is rejected (#23). Compile the pinned pickle_io.cpp and check valid and malformed pickles in exact-size buffers and in read-only spans above INT_MAX and UINT32_MAX. The valid large-span case is an expected failure until an upstream fix is pinned; a bump that fixes it fails the run until the marker goes.
This was referenced Oct 21, 2026
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.
Adds a model-free regression control for the legacy checkpoint scanner defect in #23. It does not fix the defect yet: the fix belongs in upstream
pickle_io, and this repo consumes upstream only through the submodule pin (AGENTS.md). Refs #23.Root cause
skip_pickle_objectscans GLOBAL, INST, PERSID and line-terminated operands withfind_char(p, (int)(end - p), '\n').read_torch_legacy_filepasses it the rest of the whole checkpoint, tensor storage included. AboveINT_MAXthe cast goes negative and the scan finds nothing. AboveUINT32_MAXit keeps only the low 32 bits, so short lines can pass while longer ones fail. Upstreammaster(0518b34) has the same code.Change
tests/test_pickle_span.pycompiles the pinnedpickle_io.cppwithtests/native/pickle_span_test.cppand checks:When an upstream bump fixes the scanner, the last row becomes an unexpected success and fails the run, so the marker has to be removed then. The large spans are read-only anonymous mappings, so they need no memory or data file.
Upstream fix (not in this PR)
A local patch makes
model_io::find_chartake asize_tlength, capped atINT_MAX, and drops the 13(int)(end - p)casts inpickle_io.cpp. It applies cleanly to both the pin and upstreammaster. Checked locally on macOS arm64; it has not been submitted upstream..pthwritten from SD-Turbo F16 GGUF weights is rejected by the pinned runtime (unsupported PyTorch file). The patched runtime loads it throughnew_sd_ctxin 1.6 s..pth, and flat and nested ZIP checkpoints (CPU, four threads, one step, seed 42).Validation
python3 -m unittest discover -s tests: 53 tests OK, 6 skipped, 1 expected failure (macOS arm64, Apple clang).tests.test_pickle_spanwithCXX=g++-16: OK, 1 expected failure.Scope
Test only: no
src/, export, submodule, artifact or release change. The large ZIP-checkpoint timeout in #24 is separate and untouched.