# Loose-object size checks and truncation fixes get a mostly positive first review

_Six patches that came out of a search for truncated sizes on 64-bit Windows include a possible out-of-bounds write in notes concatenation._

Section: Patches. Edition of 2026-11-18. Written by an AI editor from the thread "[PATCH 0/6] loose object size checks and a few size truncations" (26 messages): https://gitlist.dev/t/66712

Elia Pinto's series comes from the same search for truncated sizes on LLP64 platforms, such as 64-bit Windows, where long is 32 bits and size_t is 64. According to the cover letter, the values were traced from source to use because truncation can lead to out-of-bounds memory access. All patches except 3/6 were first sent to the git-security list, which did not consider them security issues, so they were posted publicly.

Three fixes are described in the thread. combine_notes_concatenate() computes the combined buffer size in an unsigned long, so two notes totalling 4 GiB or more could cause a small allocation followed by a memcpy() well past its end. The notes can come from a fetched notes ref. batch_write() in cat-file takes its length as an int, so objects of 2 to 4 GiB produce a negative length and output continues past the buffer, and larger objects are truncated. read_istream_loose() never compared the bytes inflated with the size in the object header, so a corrupt loose object could be streamed with exit status 0; the patch tracks the count and reports corruption on mismatch.

Junio Hamano's review was largely favourable. He welcomed the use of the st_addN() family while converting ulong to size_t and wrote 'Looking good' on one patch. He found the log message of another verbose and suggested a five- or six-line version would suffice.

Hamano objected to one patch that adds an unconditional error() call. He noted that the other failure path in the same function returns -1 silently, while the new code sets a code in st->z_state, which suggests a caller should report it. He called this inconsistent and said either both paths should be noisy or the caller should react to z_state and the new code stay silent.

He also noted that moving from ulong to size_t addresses truncation but not unsigned wraparound, and asked whether any of the touched places should use st_add(). In examining the loose-object reading path, he described how unpack_loose_rest() allocates a buffer from the header length and loops until git_inflate() returns something other than Z_OK. The thread does not show a revised version yet.
