diff options
author | Junio C Hamano <gitster@pobox.com> | 2019-09-09 22:26:37 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-09-09 22:26:37 +0300 |
commit | af2b8faf49ff81491872137024a464cdb7a72b10 (patch) | |
tree | 7bec2f287f48126e1a33fa981a87e61c079ae1f7 /archive-tar.c | |
parent | fa9e7934c780bc804a09bfc88a93825096b3155e (diff) | |
parent | 71d41ff651a54028856c4224777ef405de48ae66 (diff) |
Merge branch 'rs/pax-extended-header-length-fix'
"git archive" recorded incorrect length in extended pax header in
some corner cases, which has been corrected.
* rs/pax-extended-header-length-fix:
archive-tar: turn length miscalculation warning into BUG
archive-tar: use size_t in strbuf_append_ext_header()
archive-tar: fix pax extended header length calculation
archive-tar: report wrong pax extended header length
Diffstat (limited to 'archive-tar.c')
-rw-r--r-- | archive-tar.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/archive-tar.c b/archive-tar.c index 3e53aac1e6..e16d3f756d 100644 --- a/archive-tar.c +++ b/archive-tar.c @@ -142,19 +142,25 @@ static int stream_blocked(const struct object_id *oid) * string and appends it to a struct strbuf. */ static void strbuf_append_ext_header(struct strbuf *sb, const char *keyword, - const char *value, unsigned int valuelen) + const char *value, size_t valuelen) { - int len, tmp; + size_t orig_len = sb->len; + size_t len, tmp; /* "%u %s=%s\n" */ len = 1 + 1 + strlen(keyword) + 1 + valuelen + 1; - for (tmp = len; tmp > 9; tmp /= 10) + for (tmp = 1; len / 10 >= tmp; tmp *= 10) len++; strbuf_grow(sb, len); - strbuf_addf(sb, "%u %s=", len, keyword); + strbuf_addf(sb, "%"PRIuMAX" %s=", (uintmax_t)len, keyword); strbuf_add(sb, value, valuelen); strbuf_addch(sb, '\n'); + + if (len != sb->len - orig_len) + BUG("pax extended header length miscalculated as %"PRIuMAX + ", should be %"PRIuMAX, + (uintmax_t)len, (uintmax_t)(sb->len - orig_len)); } /* |