Skip to content

Commit 5848fb1

Browse files
avargitster
authored andcommitted
object-file.c: return ULHR_TOO_LONG on "header too long"
Split up the return code for "header too long" from the generic negative return value unpack_loose_header() returns, and report via error() if we exceed MAX_HEADER_LEN. As a test added earlier in this series in t1006-cat-file.sh shows we'll correctly emit zlib errors from zlib.c already in this case, so we have no need to carry those return codes further down the stack. Let's instead just return ULHR_TOO_LONG saying we ran into the MAX_HEADER_LEN limit, or other negative values for "unable to unpack <OID> header". Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3b6a8db commit 5848fb1

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

cache.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,16 +1311,19 @@ int git_open_cloexec(const char *name, int flags);
13111311
*
13121312
* - ULHR_OK on success
13131313
* - ULHR_BAD on error
1314+
* - ULHR_TOO_LONG if the header was too long
13141315
*
13151316
* It will only parse up to MAX_HEADER_LEN bytes unless an optional
13161317
* "hdrbuf" argument is non-NULL. This is intended for use with
13171318
* OBJECT_INFO_ALLOW_UNKNOWN_TYPE to extract the bad type for (error)
13181319
* reporting. The full header will be extracted to "hdrbuf" for use
1319-
* with parse_loose_header().
1320+
* with parse_loose_header(), ULHR_TOO_LONG will still be returned
1321+
* from this function to indicate that the header was too long.
13201322
*/
13211323
enum unpack_loose_header_result {
13221324
ULHR_OK,
13231325
ULHR_BAD,
1326+
ULHR_TOO_LONG,
13241327
};
13251328
enum unpack_loose_header_result unpack_loose_header(git_zstream *stream,
13261329
unsigned char *map,

object-file.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ enum unpack_loose_header_result unpack_loose_header(git_zstream *stream,
12451245
* --allow-unknown-type".
12461246
*/
12471247
if (!header)
1248-
return ULHR_BAD;
1248+
return ULHR_TOO_LONG;
12491249

12501250
/*
12511251
* buffer[0..bufsiz] was not large enough. Copy the partial
@@ -1266,7 +1266,7 @@ enum unpack_loose_header_result unpack_loose_header(git_zstream *stream,
12661266
stream->next_out = buffer;
12671267
stream->avail_out = bufsiz;
12681268
} while (status != Z_STREAM_END);
1269-
return ULHR_BAD;
1269+
return ULHR_TOO_LONG;
12701270
}
12711271

12721272
static void *unpack_loose_rest(git_zstream *stream,
@@ -1439,6 +1439,10 @@ static int loose_object_info(struct repository *r,
14391439
status = error(_("unable to unpack %s header"),
14401440
oid_to_hex(oid));
14411441
break;
1442+
case ULHR_TOO_LONG:
1443+
status = error(_("header for %s too long, exceeds %d bytes"),
1444+
oid_to_hex(oid), MAX_HEADER_LEN);
1445+
break;
14421446
}
14431447

14441448
if (status < 0) {

streaming.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ static int open_istream_loose(struct git_istream *st, struct repository *r,
235235
case ULHR_OK:
236236
break;
237237
case ULHR_BAD:
238+
case ULHR_TOO_LONG:
238239
goto error;
239240
}
240241
if (parse_loose_header(st->u.loose.hdr, &oi, 0) < 0)

t/t1006-cat-file.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,12 @@ do
356356
if test "$arg2" = "-p"
357357
then
358358
cat >expect <<-EOF
359-
error: unable to unpack $bogus_long_sha1 header
359+
error: header for $bogus_long_sha1 too long, exceeds 32 bytes
360360
fatal: Not a valid object name $bogus_long_sha1
361361
EOF
362362
else
363363
cat >expect <<-EOF
364-
error: unable to unpack $bogus_long_sha1 header
364+
error: header for $bogus_long_sha1 too long, exceeds 32 bytes
365365
fatal: git cat-file: could not get object info
366366
EOF
367367
fi &&

0 commit comments

Comments
 (0)