From: Helmut Grohne Subject: hcom: fix writing on big endian 64bit architectures On 64bit architectures, size_t is 64bit and casting a size_t pointer to an int32_t pointer will yield the upper 32 bits, which are usually zero entirely. --- a/src/hcom.c +++ b/src/hcom.c @@ -23,6 +23,7 @@ #include "sox_i.h" #include #include +#include #include #include @@ -451,12 +452,19 @@ { priv_t *p = (priv_t *) ft->priv; unsigned char *compressed_data = p->data; - size_t compressed_len = p->pos; + int32_t compressed_len; int rc = SOX_SUCCESS; + if (p->pos > INT32_MAX) { + free(p->data); + lsx_fail_errno(ft, ERANGE, "file too large for HCOM header"); + return SOX_EOF; + } + compressed_len = p->pos; + /* Compress it all at once */ if (compressed_len) - compress(ft, &compressed_data, (int32_t *)&compressed_len); + compress(ft, &compressed_data, &compressed_len); free(p->data); /* Write the header */