Skip to content

Commit ef486f1

Browse files
authored
Improve WebP detection (#733)
1 parent 67f7941 commit ef486f1

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

core.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,15 +1275,15 @@ export class FileTypeParser {
12751275

12761276
// -- 12-byte signatures --
12771277

1278-
if (this.checkString('WEBP', {offset: 8})) {
1279-
return {
1280-
ext: 'webp',
1281-
mime: 'image/webp',
1282-
};
1283-
}
1284-
12851278
// RIFF file format which might be AVI, WAV, QCP, etc
12861279
if (this.check([0x52, 0x49, 0x46, 0x46])) {
1280+
if (this.checkString('WEBP', {offset: 8})) {
1281+
return {
1282+
ext: 'webp',
1283+
mime: 'image/webp',
1284+
};
1285+
}
1286+
12871287
if (this.check([0x41, 0x56, 0x49], {offset: 8})) {
12881288
return {
12891289
ext: 'avi',

fixture/fixture-json.webp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "WEBP": {}}

test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ const falsePositives = {
281281
png: [
282282
'fixture-corrupt',
283283
],
284+
webp: [
285+
'fixture-json',
286+
],
284287
};
285288

286289
// Known failing fixture

0 commit comments

Comments
 (0)