Commit Graph

5 Commits

Author SHA1 Message Date
Alexey Tourbin
3d9823b9a4 cpio.c: fixed the integer conversion involving cpio file size
The code in question uses an improvised "strntoul" function (hidden
behind the GET_NUM_FIELD macro) which returns "int".

int cpioHeaderRead(FSM_t fsm, struct stat * st)
...
    GET_NUM_FIELD(hdr.filesize, st->st_size);

When a file size undergoes an "int bottleneck", it cannot be safely
converted back to an unsigned 64-bit integer.  By the C rules, if the
size is in the range 2G..4G-1, int becomes negative (or this may be
undefined behaviour already, I'm not a language lawyer), and conversion
to unsigned 64-bit is performed as if by adding 2^64 to the negative
value.

So you get a huge 64-bit file size.  Funnily enough, if you truncate it
to 32 bits, it's back to normal!  That's why things worked with 32-bit
size_t.

static int expandRegular(/*@special@*/ FSM_t fsm)
...
    size_t left = st->st_size;
2018-06-30 15:36:24 +03:00
Mikhail Efremov
f92be4b40e Added SELinux support
Mostly backported from rpm-4.8
2010-08-24 16:59:07 +00:00
8787ee5d55 Fixed "type qualifiers ignored on function return type" issue. 2006-05-15 02:48:59 +04:00
6cc64fa4ea updated code to snapshot 2002-06-15 of 4_0 branch 2002-08-03 16:35:14 +00:00
82a4763c66 Initial revision 2002-03-25 20:16:26 +00:00