History

mp3dec_ex: small mp3dec_detect corrections + coverage test

lieff committed 6 years ago

Commit 55da78c1 parent e46488c3 files · +19 −3Browse files

Unified · Split

3 files
  1. minimp3_ex.h +3 −3
  2. minimp3_test.c +10 −0
  3. scripts/build.sh +6 −0
minimp3_ex.h+3−3
@@ -239,9 +239,9 @@ int mp3dec_detect_cb(mp3dec_io_t *io, uint8_t *buf, size_t buf_size) · 238 unmodified lines
239239 filled = io->read(buf, MINIMP3_ID3_DETECT_SIZE, io->read_data);
240240 if (filled > MINIMP3_ID3_DETECT_SIZE)
241241 return MP3D_E_IOERROR;
242− if (MINIMP3_ID3_DETECT_SIZE != filled)
243− return MP3D_E_USER;
244242 }
243+ if (filled < MINIMP3_ID3_DETECT_SIZE)
244+ return MP3D_E_USER; /* too small, can't be mp3/mpa */
245245 if (mp3dec_skip_id3v2(buf, filled))
246246 return 0; /* id3v2 tag is enough evidence */
247247 if (io)
@@ -259,7 +259,7 @@ int mp3dec_detect_cb(mp3dec_io_t *io, uint8_t *buf, size_t buf_size) · 11 unmodified lines
259259 filled = MINIMP3_BUF_SIZE;
260260 }
261261 int free_format_bytes, frame_size;
262− mp3d_find_frame(buf, MINIMP3_MIN(filled, (size_t)INT_MAX), &free_format_bytes, &frame_size);
262+ mp3d_find_frame(buf, filled, &free_format_bytes, &frame_size);
263263 if (frame_size)
264264 return 0; /* MAX_FRAME_SYNC_MATCHES consecutive frames found */
265265 return MP3D_E_USER;
minimp3_test.c+10−0
@@ -452,6 +452,11 @@ static int self_test(const char *input_file_name) · 451 unmodified lines
452452 #define ASSERT(c) if (!(c)) { printf("failed, line=%d\n", __LINE__); exit(1); }
453453 ASSERT(1152 == samples);
454454
455+ ret = mp3dec_detect_buf(0, size);
456+ ASSERT(MP3D_E_PARAM == ret);
457+ ret = mp3dec_detect_buf(buf, (size_t)-1);
458+ ASSERT(MP3D_E_PARAM == ret);
459+
455460 ret = mp3dec_load_buf(0, buf, size, &finfo, 0, 0);
456461 ASSERT(MP3D_E_PARAM == ret);
457462 ret = mp3dec_load_buf(&mp3d, 0, size, &finfo, 0, 0);
@@ -465,6 +470,11 @@ static int self_test(const char *input_file_name) · 7 unmodified lines
465470 ret = mp3dec_load_buf(&mp3d, buf, 0, &finfo, 0, 0);
466471 ASSERT(0 == ret && 0 == finfo.samples);
467472
473+ ret = mp3dec_detect_cb(&io, 0, size);
474+ ASSERT(MP3D_E_PARAM == ret);
475+ ret = mp3dec_detect_cb(&io, buf, (size_t)-1);
476+ ASSERT(MP3D_E_PARAM == ret);
477+
468478 ret = mp3dec_load_cb(0, &io, buf, size, &finfo, 0, 0);
469479 ASSERT(MP3D_E_PARAM == ret);
470480 ret = mp3dec_load_cb(&mp3d, &io, 0, size, &finfo, 0, 0);
scripts/build.sh+6−0
@@ -102,6 +102,12 @@ rm temp.pcm · 101 unmodified lines
102102 # Delay and padding usage can be implemented if such software/files exists.
103103 [[ "$(./minimp3 vectors/l3-nonstandard-vbrtag-noframes.bit)" != "rate=44100 samples=0 max_diff=0 PSNR=99.000000" ]] && echo fail && exit 1 || echo pass
104104 [[ "$(./minimp3 -m 6 vectors/l3-nonstandard-vbrtag-noframes.bit)" != "rate=44100 samples=0 max_diff=0 PSNR=99.000000" ]] && echo fail && exit 1 || echo pass
105+
106+[[ "$(./minimp3 -m 9 vectors/l3-sin1k0db.pcm)" != "info: not an mp3/mpa file" ]] && echo fail && exit 1 || echo pass
107+[[ "$(./minimp3 -m 9 vectors/l3-nonstandard-small.bit)" != "info: not an mp3/mpa file" ]] && echo fail && exit 1 || echo pass
108+[[ "$(./minimp3 -m 11 -e 0 vectors/l3-sin1k0db.bit)" != "error: mp3dec_detect*()=-3 failed" ]] && echo fail && exit 1 || echo pass
109+[[ "$(./minimp3 -m 11 -e 1 vectors/l3-sin1k0db.bit)" != "error: mp3dec_detect*()=-3 failed" ]] && echo fail && exit 1 || echo pass
110+[[ "$(./minimp3 -m 11 -e 2 vectors/l3-sin1k0db.bit)" != "error: mp3dec_detect*()=-3 failed" ]] && echo fail && exit 1 || echo pass
105111 set -e
106112
107113 ./minimp3 -m 6 -s 215 -b vectors/l3-sin1k0db.bit vectors/l3-sin1k0db.pcm

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t