1210
return map_loose_object_1(r, NULL, oid, size);
1211
}
1212
1213
-static int unpack_loose_short_header(git_zstream *stream,
1214
- unsigned char *map, unsigned long mapsize,
1215
- void *buffer, unsigned long bufsiz)
1213
+int unpack_loose_header(git_zstream *stream,
1214
+ unsigned char *map, unsigned long mapsize,
1215
+ void *buffer, unsigned long bufsiz,
1216
+ struct strbuf *header)
1217
{
1217
- int ret;
1218
+ int status;
1219
1220
/* Get the data stream */
1221
memset(stream, 0, sizeof(*stream));
1226
1227
git_inflate_init(stream);
1228
obj_read_unlock();
1228
- ret = git_inflate(stream, 0);
1229
+ status = git_inflate(stream, 0);
1230
obj_read_lock();
1230
-
1231
- return ret;
1232
-}
1233
-
1234
-int unpack_loose_header(git_zstream *stream,
1235
- unsigned char *map, unsigned long mapsize,
1236
- void *buffer, unsigned long bufsiz)
1237
-{
1238
- int status = unpack_loose_short_header(stream, map, mapsize,
1239
- buffer, bufsiz);
1240
-
1241
- if (status < Z_OK)
1242
- return -1;
1243
-
1244
- /* Make sure we have the terminating NUL */
1245
- if (!memchr(buffer, '\0', stream->next_out - (unsigned char *)buffer))
1246
- return -1;
1247
- return 0;
1248
-}
1249
-
1250
-static int unpack_loose_header_to_strbuf(git_zstream *stream, unsigned char *map,
1251
- unsigned long mapsize, void *buffer,
1252
- unsigned long bufsiz, struct strbuf *header)
1253
-{
1254
- int status;
1255
-
1256
- status = unpack_loose_short_header(stream, map, mapsize, buffer, bufsiz);
1231
if (status < Z_OK)
1232
return -1;
1233
1237
if (memchr(buffer, '\0', stream->next_out - (unsigned char *)buffer))
1238
return 0;
1239
1240
+ /*
1241
+ * We have a header longer than MAX_HEADER_LEN. The "header"
1242
+ * here is only non-NULL when we run "cat-file
1243
+ * --allow-unknown-type".
1244
+ */
1245
+ if (!header)
1246
+ return -1;
1247
+
1248
/*
1249
* buffer[0..bufsiz] was not large enough. Copy the partial
1250
* result out to header, and then append the result of further
1394
char hdr[MAX_HEADER_LEN];
1395
struct strbuf hdrbuf = STRBUF_INIT;
1396
unsigned long size_scratch;
1397
+ int allow_unknown = flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE;
1398
1399
if (oi->delta_base_oid)
1400
oidclr(oi->delta_base_oid);
1428
1429
if (oi->disk_sizep)
1430
*oi->disk_sizep = mapsize;
1448
- if ((flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE)) {
1449
- if (unpack_loose_header_to_strbuf(&stream, map, mapsize, hdr, sizeof(hdr), &hdrbuf) < 0)
1450
- status = error(_("unable to unpack %s header with --allow-unknown-type"),
1451
- oid_to_hex(oid));
1452
- } else if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
1431
+
1432
+ if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr),
1433
+ allow_unknown ? &hdrbuf : NULL) < 0)
1434
status = error(_("unable to unpack %s header"),
1435
oid_to_hex(oid));
1436
if (status < 0)
2531
goto out;
2532
}
2533
2553
- if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0) {
2534
+ if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr),
2535
+ NULL) < 0) {
2536
error(_("unable to unpack header of %s"), path);
2537
goto out;
2538
}