diff options
author | Jeff King <peff@peff.net> | 2025-02-25 01:30:56 -0500 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2025-02-25 10:24:55 -0800 |
commit | 67a6b1aeb82fd4685e862a3a7807d4ed8ea5d899 (patch) | |
tree | 4754a28683b4af345d51b34b2fd7a89f7869c2a3 /object-file.c | |
parent | 0b1493c2d49222ce07b73016bb156fecb5999bb9 (diff) |
unpack_loose_header(): avoid numeric comparison of zlib status
When unpacking a loose header, we try to inflate the first 32 bytes.
We'd expect either Z_OK (we filled up the output buffer, but there are
more bytes in the object) or Z_STREAM_END (this is a tiny object whose
header and content fit in the buffer).
We check for that with "if (status < Z_OK)", making the assumption that
all of the errors we'd see have negative values (as Z_OK itself is "0",
and Z_STREAM_END is "1").
But there's at least one case this misses: Z_NEED_DICT is "2". This
isn't something we'd ever expect to see, but if we do see it, we should
consider it an error (since we have no dictionary to load).
Instead, the current code interprets Z_NEED_DICT as success and looks
for the object header's terminating NUL in the bytes we've read. This
will generaly be zero bytes if the dictionary is mentioned at the start
of the stream. So we'll fail to find it and complain "the header is too
long" (ULHR_LONG). But really, the problem is that the object is
malformed, and we should return ULHR_BAD.
This is a minor bug, as we consider both cases to be an error. But it
does mean we print the wrong error message. The test case added in the
previous patch triggers this code, so we can just confirm the error
message we see here.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'object-file.c')
-rw-r--r-- | object-file.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/object-file.c b/object-file.c index 5086633e21..0bc62b53d3 100644 --- a/object-file.c +++ b/object-file.c @@ -1273,7 +1273,7 @@ enum unpack_loose_header_result unpack_loose_header(git_zstream *stream, obj_read_unlock(); status = git_inflate(stream, 0); obj_read_lock(); - if (status < Z_OK) + if (status != Z_OK && status != Z_STREAM_END) return ULHR_BAD; /* |