diff --git a/lib/parse_stream/bmp.js b/lib/parse_stream/bmp.js index e112ea1..be01539 100644 --- a/lib/parse_stream/bmp.js +++ b/lib/parse_stream/bmp.js @@ -21,8 +21,8 @@ module.exports = function () { } parser.push({ - width: data.readUInt16LE(18), - height: data.readUInt16LE(22), + width: data.readInt32LE(18), + height: Math.abs(data.readInt32LE(22)), type: 'bmp', mime: 'image/bmp', wUnits: 'px', diff --git a/lib/parse_sync/bmp.js b/lib/parse_sync/bmp.js index 46b988a..f93f4d8 100644 --- a/lib/parse_sync/bmp.js +++ b/lib/parse_sync/bmp.js @@ -4,7 +4,7 @@ var str2arr = require('../common').str2arr; var sliceEq = require('../common').sliceEq; -var readUInt16LE = require('../common').readUInt16LE; +var readUInt32LE = require('../common').readUInt32LE; var SIG_BM = str2arr('BM'); @@ -15,8 +15,8 @@ module.exports = function (data) { if (!sliceEq(data, 0, SIG_BM)) return; return { - width: readUInt16LE(data, 18), - height: readUInt16LE(data, 22), + width: readUInt32LE(data, 18), + height: Math.abs(readUInt32LE(data, 22)), type: 'bmp', mime: 'image/bmp', wUnits: 'px', diff --git a/test/fixtures/iojs_logo_flip_row_order.bmp b/test/fixtures/iojs_logo_flip_row_order.bmp new file mode 100644 index 0000000..8833a0f Binary files /dev/null and b/test/fixtures/iojs_logo_flip_row_order.bmp differ diff --git a/test/test_formats.js b/test/test_formats.js index 37722d4..b66f684 100644 --- a/test/test_formats.js +++ b/test/test_formats.js @@ -21,6 +21,15 @@ describe('File formats', function () { assert.deepStrictEqual(size, { width: 367, height: 187, type: 'bmp', mime: 'image/bmp', wUnits: 'px', hUnits: 'px' }); }); + + + it('should get correct size on flip row order BMP', async function () { + let file = path.join(__dirname, 'fixtures', 'iojs_logo_flip_row_order.bmp'); + + let size = await probe(fs.createReadStream(file)); + + assert.deepStrictEqual(size, { width: 367, height: 187, type: 'bmp', mime: 'image/bmp', wUnits: 'px', hUnits: 'px' }); + }); }); @@ -31,6 +40,14 @@ describe('File formats', function () { assert.deepStrictEqual(size, { width: 367, height: 187, type: 'bmp', mime: 'image/bmp', wUnits: 'px', hUnits: 'px' }); }); + + + it('should get correct size on flip row order BMP', function () { + let file = path.join(__dirname, 'fixtures', 'iojs_logo_flip_row_order.bmp'); + let size = probe.sync(fs.readFileSync(file)); + + assert.deepStrictEqual(size, { width: 367, height: 187, type: 'bmp', mime: 'image/bmp', wUnits: 'px', hUnits: 'px' }); + }); });