diff --git a/lib/processImage.js b/lib/processImage.js index 7fc889d..152cdde 100644 --- a/lib/processImage.js +++ b/lib/processImage.js @@ -365,6 +365,20 @@ module.exports = (options) => { detectedContentType = 'image/png'; } else if (firstChunk[0] === 0x42 && firstChunk[1] === 0x4d) { detectedContentType = 'image/bmp'; + } else if ( + firstChunk[0] === 0x0 && + firstChunk[1] === 0x0 && + firstChunk[2] === 0x1 && + firstChunk[3] === 0x0 + ) { + detectedContentType = 'image/x-icon'; + } else if ( + firstChunk[8] === 0x57 && + firstChunk[9] === 0x45 && + firstChunk[10] === 0x42 && + firstChunk[11] === 0x50 + ) { + detectedContentType = 'image/webp'; } if ( detectedContentType && diff --git a/reallyaico.gif b/reallyaico.gif new file mode 100644 index 0000000..a087fa0 Binary files /dev/null and b/reallyaico.gif differ diff --git a/reallyawebp.png b/reallyawebp.png new file mode 100644 index 0000000..a608fc8 Binary files /dev/null and b/reallyawebp.png differ diff --git a/test/processImage.js b/test/processImage.js index 1c1a289..a3426f7 100644 --- a/test/processImage.js +++ b/test/processImage.js @@ -1386,6 +1386,36 @@ describe('express-processimage', () => { beforeEach(() => { config.secondGuessSourceContentType = true; }); + it('should recover gracefully when attempting to process a wrongly named webp', () => { + return expect('GET /reallyawebp.png?metadata', 'to yield response', { + body: { + format: 'webp', + size: 176972, + width: 1024, + height: 772, + space: 'srgb', + channels: 3, + depth: 'uchar', + isProgressive: false, + hasProfile: false, + hasAlpha: false, + contentType: 'image/webp', + filesize: 176972, + etag: 'W/"2b34c-18e564af60c"' + } + }); + }); + it('should return the correct contentType of a wrongly named ico', () => { + return expect('GET /reallyaico.gif?metadata', 'to yield response', { + body: { + error: 'Input buffer contains unsupported image format', + format: 'ico', + contentType: 'image/x-icon', + filesize: 67646, + etag: 'W/"1083e-18d82105007"' + } + }); + }); it('should recover gracefully when attempting to process a wrongly named jpeg', () => { config.debug = true; return expect('GET /reallyajpeg.gif?resize=40,35', 'to yield response', {