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
239 filled = io->read(buf, MINIMP3_ID3_DETECT_SIZE, io->read_data);239 filled = io->read(buf, MINIMP3_ID3_DETECT_SIZE, io->read_data);
240 if (filled > MINIMP3_ID3_DETECT_SIZE)240 if (filled > MINIMP3_ID3_DETECT_SIZE)
241 return MP3D_E_IOERROR;241 return MP3D_E_IOERROR;
242 if (MINIMP3_ID3_DETECT_SIZE != filled)
243 return MP3D_E_USER;
244 }242 }
243 if (filled < MINIMP3_ID3_DETECT_SIZE)
244 return MP3D_E_USER; /* too small, can't be mp3/mpa */
245 if (mp3dec_skip_id3v2(buf, filled))245 if (mp3dec_skip_id3v2(buf, filled))
246 return 0; /* id3v2 tag is enough evidence */246 return 0; /* id3v2 tag is enough evidence */
247 if (io)247 if (io)
@@ -259,7 +259,7 @@ int mp3dec_detect_cb(mp3dec_io_t *io, uint8_t *buf, size_t buf_size) · 11 unmodified lines
259 filled = MINIMP3_BUF_SIZE;259 filled = MINIMP3_BUF_SIZE;
260 }260 }
261 int free_format_bytes, frame_size;261 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);
263 if (frame_size)263 if (frame_size)
264 return 0; /* MAX_FRAME_SYNC_MATCHES consecutive frames found */264 return 0; /* MAX_FRAME_SYNC_MATCHES consecutive frames found */
265 return MP3D_E_USER;265 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
452#define ASSERT(c) if (!(c)) { printf("failed, line=%d\n", __LINE__); exit(1); }452#define ASSERT(c) if (!(c)) { printf("failed, line=%d\n", __LINE__); exit(1); }
453 ASSERT(1152 == samples);453 ASSERT(1152 == samples);
454 454
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
455 ret = mp3dec_load_buf(0, buf, size, &finfo, 0, 0);460 ret = mp3dec_load_buf(0, buf, size, &finfo, 0, 0);
456 ASSERT(MP3D_E_PARAM == ret);461 ASSERT(MP3D_E_PARAM == ret);
457 ret = mp3dec_load_buf(&mp3d, 0, size, &finfo, 0, 0);462 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
465 ret = mp3dec_load_buf(&mp3d, buf, 0, &finfo, 0, 0);470 ret = mp3dec_load_buf(&mp3d, buf, 0, &finfo, 0, 0);
466 ASSERT(0 == ret && 0 == finfo.samples);471 ASSERT(0 == ret && 0 == finfo.samples);
467 472
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
468 ret = mp3dec_load_cb(0, &io, buf, size, &finfo, 0, 0);478 ret = mp3dec_load_cb(0, &io, buf, size, &finfo, 0, 0);
469 ASSERT(MP3D_E_PARAM == ret);479 ASSERT(MP3D_E_PARAM == ret);
470 ret = mp3dec_load_cb(&mp3d, &io, 0, size, &finfo, 0, 0);480 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
102# Delay and padding usage can be implemented if such software/files exists.102# Delay and padding usage can be implemented if such software/files exists.
103[[ "$(./minimp3 vectors/l3-nonstandard-vbrtag-noframes.bit)" != "rate=44100 samples=0 max_diff=0 PSNR=99.000000" ]] && echo fail && exit 1 || echo pass103[[ "$(./minimp3 vectors/l3-nonstandard-vbrtag-noframes.bit)" != "rate=44100 samples=0 max_diff=0 PSNR=99.000000" ]] && echo fail && exit 1 || echo pass
104[[ "$(./minimp3 -m 6 vectors/l3-nonstandard-vbrtag-noframes.bit)" != "rate=44100 samples=0 max_diff=0 PSNR=99.000000" ]] && echo fail && exit 1 || echo pass104[[ "$(./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
105set -e111set -e
106 112
107./minimp3 -m 6 -s 215 -b vectors/l3-sin1k0db.bit vectors/l3-sin1k0db.pcm113./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