From: Jeff King Date: Mon, 25 Mar 2013 21:26:05 GMT Subject: Re: [PATCH 5/9] add test for streaming corrupt blobs Message-ID: <20130325212605.GA19303@sigill.intra.peff.net> In-Reply-To: <20130325211038.GD1414@google.com> On Mon, Mar 25, 2013 at 02:10:38PM -0700, Jonathan Nieder wrote: > > +# convert "1234abcd" to ".git/objects/12/34abcd" > > +obj_to_file() { > > + echo "$(git rev-parse --git-dir)/objects/$(git rev-parse "$1" | sed 's,..,&/,')" > > +} > > Maybe this would be clearer in multiple lines? > > commit=$(git rev-parse --verify "$1") && > git_dir=$(git rev-parse --git-dir) && > tail=${commit#??} && > echo "$git_dir/objects/${commit%$tail}/$tail" Yeah, it started as: echo "$1" | sed 's,..,&/,' and kind of got out of hand as it grew features. I'd be fine with your version (though $commit is not right, as it is any object, and in fact the test uses blobs). > > + > > +# Convert byte at offset "$2" of object "$1" into '\0' > > +corrupt_byte() { > > + obj_file=$(obj_to_file "$1") && > > + chmod +w "$obj_file" && > > + printf '\0' | dd of="$obj_file" bs=1 seek="$2" > > Some other tests such as t4205 also rely on "printf" being > binary-safe. Phew. Yeah, I think it should be fine, though the choice of character does not actually matter, as long as it is different from what is currently at that position (for the sake of simplicity, I just determined experimentally that the given object is corrupted with the offset and character I chose). -Peff