Skip to content

Commit e7ac344

Browse files
peffgitster
authored andcommitted
unpack_loose_header(): report headers without NUL as "bad"
If a caller asks us to read the whole loose object header value into a strbuf (e.g., via "cat-file --allow-unknown-type"), we'll keep reading until we see a NUL byte marking the end of the header. If we hit Z_STREAM_END before seeing the NUL, we obviously have to stop. But we return ULHR_TOO_LONG, which doesn't make any sense. The "too long" return code is used in the normal, 32-byte limited mode to indicate that we stopped looking. There is no such thing as "too long" here, as we'd keep reading forever until we see the end of stream or the NUL. Instead, we should return ULHR_BAD. The loose object has no NUL marking the end of header, so it is malformed. The behavior difference is slight; in either case we'd consider the object unreadable and refuse to go further. The only difference is the specific error message we produce. There's no test case here, as we'd need to generate a valid zlib stream without a NUL. That's not something Git will do without writing new custom code. And in the next patch we'll fix another bug in this area which will make this easier to do (and we will test it then). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 03e7c45 commit e7ac344

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

object-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ enum unpack_loose_header_result unpack_loose_header(git_zstream *stream,
13081308
if (memchr(buffer, '\0', stream->next_out - (unsigned char *)buffer))
13091309
return 0;
13101310
} while (status != Z_STREAM_END);
1311-
return ULHR_TOO_LONG;
1311+
return ULHR_BAD;
13121312
}
13131313

13141314
static void *unpack_loose_rest(git_zstream *stream,

0 commit comments

Comments
 (0)