Re: [PATCH v3 1/4] t5000: test tar files that overflow ustar headers
- From
Jeff King <peff@peff.net>
- Date
- Jun 24, 2016, 20:58 UTC
- Message-ID
- <20160624205858.GA23315@sigill.intra.peff.net>
- In-Reply-To
- <20160624190744.GA32118@sigill.intra.peff.net>
On Fri, Jun 24, 2016 at 03:07:44PM -0400, Jeff King wrote:
Show 6 quoted lines
> > "dd bs=1 count=4096" is hopefully more portable. > > Hmm. I always wonder whether dd is actually very portable, but we do use > it already, at least. > > Perhaps the perl monstrosity in t9300 could be replaced with that, too.
Hrm. So I wrote a patch for t9300 for this. But I wanted to flip the order to:
dd bs=4096 count=1
because otherwise, dd will call read() 4096 times, for 1 byte each.
But it's not safe to do that on a pipe. For example:
{
echo 1
sleep 1
echo 2
} | dd bs=4 count=1will copy only 2 bytes. So it's racily wrong, depending on how the writer feeds the data to write().
The 1-byte reads do work (assuming blocking descriptors and that dd restarts a read after a signal, which mine seems to). But yuck.
The difference in time between the two is measurable on my system, but it's only a few milliseconds (for 4096 bytes). So maybe it's not worth worrying about (though as a general technique, it does make me worry that it's easy to get wrong in a way that will fail racily).
-Peff