Skip to content

Commit 307b4f6

Browse files
authored
Merge pull request #1 from closeio/relax_mp3_detection_algorithm
Relax mp3 detection algorithm since it had false negatives
2 parents 74820c4 + de6b891 commit 307b4f6

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2016 Close.io
3+
Copyright (c) 2018 Close.io
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function(filevalidator) {
1818

1919
fileInput.addEventListener('change', function(e) {
2020
var file = e.currentTarget.files[0];
21-
FileDetector.verifyFileType(file, ['mp3', 'wav'], function(valid) {
21+
filevalidator.verifyFileType(file, ['mp3', 'wav'], function(valid) {
2222
alert('Valid mp3 or wave file: ' + !!valid);
2323
});
2424
});

filevalidator.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ function(_) {
1111
// MPEG-1 Layer 3 file without an ID3 tag or with an ID3v1 tag (which's appended at the end of the file)
1212
[0xFF, 0xFB],
1313
// MP3 file with an ID3v2 container
14-
[0x49, 0x44, 0x33]
14+
[0x49, 0x44, 0x33],
15+
// Other MP3 files (FF Fx and FF Ex – they may cause false-positives)
16+
// Headers taken from https://www.garykessler.net/library/file_sigs.html
17+
[0xFF, 0xE0], [0xFF, 0xE1], [0xFF, 0xE2], [0xFF, 0xE3], [0xFF, 0xE4],
18+
[0xFF, 0xE5], [0xFF, 0xE6], [0xFF, 0xE7], [0xFF, 0xE8], [0xFF, 0xE9],
19+
[0xFF, 0xEA], [0xFF, 0xEB], [0xFF, 0xEC], [0xFF, 0xED], [0xFF, 0xEE], [0xFF, 0xEF],
20+
[0xFF, 0xF0], [0xFF, 0xF1], [0xFF, 0xF2], [0xFF, 0xF3], [0xFF, 0xF4],
21+
[0xFF, 0xF5], [0xFF, 0xF6], [0xFF, 0xF7], [0xFF, 0xF8], [0xFF, 0xF9],
22+
[0xFF, 0xFA], [0xFF, 0xFB], [0xFF, 0xFC], [0xFF, 0xFD], [0xFF, 0xFE], [0xFF, 0xFF]
1523
],
1624
'wav': [
1725
// Waveform Audio File Format

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
{
22
"name": "filevalidator",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "File signature validation in JavaScript",
55
"main": "filevalidator.js",
6-
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
8-
},
96
"author": "Phil Freo <phil@philfreo.com> (http://philfreo.com/)",
107
"license": "MIT"
118
}

0 commit comments

Comments
 (0)