← Winnitude! Search  ·  Reader Mode (2274 ms)
Links: Stay in Reader Retro Site Converter Retro Mode: OFF Original Page ↗
GITHUB · 1 LINKS

fix: validate object types when loading binary SHAs by Byron · Pull Request #2256 · gitpython-developers/GitPython

Tasks This section is for Byron only. Models continuing this PR must not add, remove, check, uncheck, rename, or reorder checkboxes here. refackiew Everything below this line was generated by Codex GPT-6. Created by Codex on behalf of Byron. Byron will review before this is ready to merge. Fixes #2254. Commit(repo, tag.binsha).tree now raises a ValueError identifying the SHA, its actual type, and the expected type before parsing tag data as a commit. The shared check also covers trees, tags, blobs, object size/streams, and raw tree traversal. Validation happens on first data access, preserving lazy constructors and placeholder objects. Rejected streams are drained so subsequent git cat-file reads remain usable even while an exception retains its traceback. The related audit found two more cases: IndexFile.new() converted binary SHAs to their Python string representation, and submodule diffs wrapped commit SHAs in Blob objects. Index creation now accepts binary SHAs and hexadecimal bytes alongside strings and trees; submodule diffs use IndexObject entries while retaining access to the submodule's commit data. Existing object, index, and submodule diff tests were extended in place, including mixed binary/hex/tree arguments. No new test functions were added. Validation: 227 affected tests passed, with 2 skips, across the suite run and the staged-file test's rerun with init.defaultBranch=master. Commit signing was disabled only for test commands. The extended object and index tests failed before the fix. The issue reproduction and valid binary-SHA operations were also checked with both GitCmdObjectDB and GitDB. Ruff lint/format checks, mypy (46 source files), and basedpyright passed. The now-obsolete index assignment diagnostic was removed from the type-checking baseline. Codex review of ca55dbf found no actionable regressions. Git behavior reference: d38352cd43ab9745686d697872408bc3249a153f in the local Git checkout; the commit, tree, and tag readers check object types before parsing their contents.

Skip to content

Repository navigation