pr-git-2350/wufengwind/object-map-insert-validation-v1
tagged this
26 Jun 15:58
From: Feng Wu <wufengwufengwufeng@gmail.com> The loose object map stores entries keyed by the repository's storage hash and the compatible hash. ObjectMap::insert() accepts its two object IDs in either order, but it currently checks only whether oid1 uses the compatible hash algorithm. If it does not, oid2 is assumed to be the compatible ID without validating oid2's algorithm. That means callers can pass two IDs with the same algorithm, or an ID using an unknown algorithm, and have one of them silently treated as the storage ID. This does not match the map invariant that each entry must contain exactly one storage hash and one compatible hash. Make the invariant explicit by decoding both object ID algorithms and rejecting unknown or mismatched pairs before inserting anything. Introduce ObjectMapInsertError with InvalidHashAlgorithm and MismatchedAlgorithms variants for clear error reporting. Update the existing tests to unwrap successful insertions, and add tests for same-algorithm and unknown-algorithm inputs. Signed-off-by: Feng Wu <wufengwufengwufeng@gmail.com> Submitted-As: https://lore.kernel.org/git/pull.2350.git.git.1782489506255.gitgitgadget@gmail.com