Skip to content

Commit ec45680

Browse files
jkbonfielddaviesrob
authored andcommitted
r4x16pr: protect against input being NULL and in_size of zero.
This is a very esoteric case, and arguably we could just state that the function is invalid if given a NULL pointer, but the undefined behaviour sanitizer complains about memcpy of NULL even when copying zero bytes.
1 parent 56b4096 commit ec45680

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

htscodecs/rANS_static4x16pr.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,8 @@ unsigned char *rans_compress_to_4x16(unsigned char *in, unsigned int in_size,
12671267
out[0] = RANS_ORDER_CAT;
12681268
c_meta_len = 1;
12691269
c_meta_len += var_put_u32(&out[1], out_end, in_size);
1270-
memcpy(out+c_meta_len, in, in_size);
1270+
if (in_size)
1271+
memcpy(out+c_meta_len, in, in_size);
12711272
*out_size = c_meta_len + in_size;
12721273
return out;
12731274
}
@@ -1380,7 +1381,8 @@ unsigned char *rans_compress_to_4x16(unsigned char *in, unsigned int in_size,
13801381
if (*out_size >= in_size) {
13811382
out[0] &= ~3;
13821383
out[0] |= RANS_ORDER_CAT | no_size;
1383-
memcpy(out+c_meta_len, in, in_size);
1384+
if (in_size)
1385+
memcpy(out+c_meta_len, in, in_size);
13841386
*out_size = in_size;
13851387
}
13861388

0 commit comments

Comments
 (0)