Message ID | pull.1158.v2.git.1645661240356.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 0cf5fbc2e4ee124b4dc583fac6f7ad697616a56a |
Headers | show |
Series | [v2] index-pack: clarify the breached limit | expand |
On Thu, Feb 24 2022, Matt Cooper via GitGitGadget wrote: > From: Matt Cooper <vtbassmatt@gmail.com> > [...] > +test_expect_success 'too-large packs report the breach' ' > + pack=$(git pack-objects --all pack </dev/null) && > + sz="$(test_file_size pack-$pack.pack)" && I don't think this needs a re-roll, but FWIW I have an old-ish local patch I haven't submitted yet to s/test_file_size/test-tool path-utils file-size/g in the test suite. I.e. we've been moving more in the direction of using test-tool directly, which some tests already do in that case, with some using test_file_size. > + test "$sz" -gt 20 && > + test_must_fail git index-pack --max-input-size=20 pack-$pack.pack 2>err && > + grep "maximum allowed size (20 bytes)" err > +' Maybe this is covered by another test, but in case we don't have a test for this error already: This doesn't cover that we don't error on packs smaller than the limit, so in terms of black-box testing it's indistinguishable from us erroring out about this all the time. But that's probably too paranoid in the first place, and maybe we do have that other test...
diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 3c2e6aee3cc..c45273de3b1 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -323,8 +323,12 @@ static void use(int bytes) if (signed_add_overflows(consumed_bytes, bytes)) die(_("pack too large for current definition of off_t")); consumed_bytes += bytes; - if (max_input_size && consumed_bytes > max_input_size) - die(_("pack exceeds maximum allowed size")); + if (max_input_size && consumed_bytes > max_input_size) { + struct strbuf size_limit = STRBUF_INIT; + strbuf_humanise_bytes(&size_limit, max_input_size); + die(_("pack exceeds maximum allowed size (%s)"), + size_limit.buf); + } } static const char *open_pack_file(const char *pack_name) diff --git a/t/t5302-pack-index.sh b/t/t5302-pack-index.sh index 8ee67df38f6..b0095ab41d3 100755 --- a/t/t5302-pack-index.sh +++ b/t/t5302-pack-index.sh @@ -284,4 +284,12 @@ test_expect_success 'index-pack -v --stdin produces progress for both phases' ' test_i18ngrep "Resolving deltas" err ' +test_expect_success 'too-large packs report the breach' ' + pack=$(git pack-objects --all pack </dev/null) && + sz="$(test_file_size pack-$pack.pack)" && + test "$sz" -gt 20 && + test_must_fail git index-pack --max-input-size=20 pack-$pack.pack 2>err && + grep "maximum allowed size (20 bytes)" err +' + test_done