Merge branch 'jk/pack-header-parse-alignment-fix'

It was possible for "git unpack-objects" and "git index-pack" to
make an unaligned access, which has been corrected.

* jk/pack-header-parse-alignment-fix:
  index-pack, unpack-objects: use skip_prefix to avoid magic number
  index-pack, unpack-objects: use get_be32() for reading pack header
  parse_pack_header_option(): avoid unaligned memory writes
  packfile: factor out --pack_header argument parsing
  bswap.h: squelch potential sparse -Wcast-truncate warnings
This commit is contained in:
Junio C Hamano
2025-01-28 13:02:23 -08:00
6 changed files with 64 additions and 50 deletions

View File

@ -2315,3 +2315,23 @@ int is_promisor_object(struct repository *r, const struct object_id *oid)
}
return oidset_contains(&promisor_objects, oid);
}
int parse_pack_header_option(const char *in, unsigned char *out, unsigned int *len)
{
unsigned char *hdr;
char *c;
hdr = out;
put_be32(hdr, PACK_SIGNATURE);
hdr += 4;
put_be32(hdr, strtoul(in, &c, 10));
hdr += 4;
if (*c != ',')
return -1;
put_be32(hdr, strtoul(c + 1, &c, 10));
hdr += 4;
if (*c)
return -1;
*len = hdr - out;
return 0;
}