t: add library for munging chunk-format files
commit86b008ee61ccf800f613d7de382bd9e3b6bbaa6f
authorJeff King <peff@peff.net>
Mon, 9 Oct 2023 20:58:38 +0000 (9 16:58 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 9 Oct 2023 22:55:00 +0000 (9 15:55 -0700)
tree78c89ba797a28257fd20266824c9f22a39571d8f
parent570b8b883617df2acfedab88b9f5af0b50c821cd
t: add library for munging chunk-format files

When testing corruption of files using the chunk format (like
commit-graphs and midx files), it's helpful to be able to modify bytes
in specific chunks. This requires being able both to read the
table-of-contents (to find the chunk to modify) but also to adjust it
(to account for size changes in the offsets of subsequent chunks).

We have some tests already which corrupt chunk files, but they have some
downsides:

  1. They are very brittle, as they manually compute the expected size
     of a particular instance of the file (e.g., see the definitions
     starting with NUM_OBJECTS in t5319).

  2. Because they rely on manual offsets and don't read the
     table-of-contents, they're limited to overwriting bytes. But there
     are many interesting corruptions that involve changing the sizes of
     chunks (especially smaller-than-expected ones).

This patch adds a perl script which makes such corruptions easy. We'll
use it in subsequent patches.

Note that we could get by with just a big "perl -e" inside the helper
function. I chose to put it in a separate script for two reasons. One,
so we don't have to worry about the extra layer of shell quoting. And
two, the script is kind of big, and running the tests with "-x" would
repeatedly dump it into the log output.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/lib-chunk.sh [new file with mode: 0644]
t/lib-chunk/corrupt-chunk-file.pl [new file with mode: 0644]