Change th_get_size() macro to return unsigned int
commite4c1f2974258d6a325622cfd712873d49b5e7a73
authorChris Frey <cdfrey@foursquare.net>
Thu, 24 Oct 2013 22:52:44 +0000 (24 18:52 -0400)
committerChris Frey <cdfrey@foursquare.net>
Mon, 18 Nov 2013 05:28:36 +0000 (18 00:28 -0500)
treeda9f0b06a21b76363f2595a37c6b2cf13e99bb95
parent7c3b3453bf81a424a1fa9659c81977cb091f3296
Change th_get_size() macro to return unsigned int

On systems where size_t is larger than an int (and larger than
unsigned int), then in various places in the library, where
stuff like this happens:

size_t sz = th_get_size(t);

then the int value returned from th_get_size() is sign extended to
some unwieldy amount.

On 64bit systems, this can yield extremely large values.

By fixing this problem in the header, and only for th_get_size(),
we avoid breaking the API of the function call oct_to_int()
(which arguably should return an unsigned int, since the sscanf()
it uses expects to yield an unsigned int).  We also fix the library,
which uses th_get_size() internally to assign sizes to size_t.

The drawback is that not all client code that uses th_get_size()
will be fixed, until they recompile, but they will automatically
take advantage of the bugs fixed *inside* the library.

The remaining th_get_*() functions operate on modes and CRC values
and the like, and should be fine, remaining as ints.

Thanks very much to Magnus Holmgren for catching this behaviour.
https://lists.feep.net:8080/pipermail/libtar/2013-October/000365.html
lib/libtar.h