summaryrefslogtreecommitdiffstats
path: root/sbc
diff options
context:
space:
mode:
authorSiarhei Siamashka <siarhei.siamashka@gmail.com>2009-01-18 23:10:00 +0200
committerMarcel Holtmann <marcel@holtmann.org>2009-01-19 13:03:41 +0100
commit906a4655cc998bb4ef8f23f4e62ce916d37f7caa (patch)
treedc22a9698006c73441598bc91e2565fa5918bbd5 /sbc
parenta8c57dbfeb6d2c5f6a160df812aacd2983fde6d1 (diff)
Fix sbcenc breakage when au file header size is larger than 24 bytes
Diffstat (limited to 'sbc')
-rw-r--r--sbc/sbcenc.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/sbc/sbcenc.c b/sbc/sbcenc.c
index 388be2a4..fba9be30 100644
--- a/sbc/sbcenc.c
+++ b/sbc/sbcenc.c
@@ -48,7 +48,13 @@ static void encode(char *filename, int subbands, int bitpool, int joint,
{
struct au_header au_hdr;
sbc_t sbc;
- int fd, len, size, count, encoded, srate, codesize, nframes;
+ int fd, len, size, encoded, srate, codesize, nframes;
+
+ if (sizeof(au_hdr) != 24) {
+ /* Sanity check just in case */
+ fprintf(stderr, "FIXME: sizeof(au_hdr) != 24\n");
+ return;
+ }
if (strcmp(filename, "-")) {
fd = open(filename, O_RDONLY);
@@ -72,7 +78,7 @@ static void encode(char *filename, int subbands, int bitpool, int joint,
if (au_hdr.magic != AU_MAGIC ||
BE_INT(au_hdr.hdr_size) > 128 ||
- BE_INT(au_hdr.hdr_size) < 24 ||
+ BE_INT(au_hdr.hdr_size) < sizeof(au_hdr) ||
BE_INT(au_hdr.encoding) != AU_FMT_LIN16) {
fprintf(stderr, "Not in Sun/NeXT audio S16_BE format\n");
goto done;
@@ -119,9 +125,9 @@ static void encode(char *filename, int subbands, int bitpool, int joint,
}
sbc.endian = SBC_BE;
- count = BE_INT(au_hdr.data_size);
- size = len - BE_INT(au_hdr.hdr_size);
- memmove(input, input + BE_INT(au_hdr.hdr_size), size);
+ /* Skip extra bytes of the header if any */
+ if (read(fd, input, BE_INT(au_hdr.hdr_size) - len) < 0)
+ goto done;
sbc.bitpool = bitpool;
sbc.allocation = snr ? SBC_AM_SNR : SBC_AM_LOUDNESS;
@@ -177,8 +183,12 @@ static void encode(char *filename, int subbands, int bitpool, int joint,
perror("Can't write SBC output");
break;
}
- if (size >= codesize) {
- /* sbc_encode failure has been detected earlier */
+ if (size != 0) {
+ /*
+ * sbc_encode failure has been detected earlier or end
+ * of file reached (have trailing partial data which is
+ * insufficient to encode SBC frame)
+ */
break;
}
}