Skip to content

Commit

Permalink
Ensure support for little endian without 'Exif\0\0' prefix (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell authored Jan 28, 2024
1 parent 27420cb commit 4ca59e2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var tags = require('./tags');

module.exports = function (buffer) {
var startingOffset = 0;
if (buffer.toString('ascii', 0, 3) !== 'MM\0' && buffer.toString('ascii', 0, 3) !== 'II\0') {
if (buffer.toString('ascii', 0, 3) !== 'MM\0' && buffer.toString('ascii', 0, 3) !== 'II\x2a') {
startingOffset = 6;
if (buffer.toString('ascii', 0, 5) !== 'Exif\0')
throw new Error('Invalid EXIF data: buffer should start with "Exif", "MM" or "II".');
Expand Down
Binary file added test/data/little-endian.exif
Binary file not shown.
24 changes: 24 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var tetons = fs.readFileSync(__dirname + '/data/tetons.exif');
var IMG_0774 = fs.readFileSync(__dirname + '/data/IMG_0774.exif');
var pngWithExif = fs.readFileSync(__dirname + '/data/png-exif.exif');
var non_ascii = fs.readFileSync(__dirname + '/data/non-ascii.exif');
var littleEndian = fs.readFileSync(__dirname + '/data/little-endian.exif');

describe('exif-reader', function () {
it('should read tiff and exif data', function () {
Expand Down Expand Up @@ -234,6 +235,29 @@ describe('exif-reader', function () {
});
});

it('should read little endian data', function () {
expect(exif(littleEndian), 'to equal', {
bigEndian: false,
Image: {
Orientation: 1,
XResolution: 25.4,
YResolution: 25.4,
ResolutionUnit: 2,
Software: 'sharp',
YCbCrPositioning: 1,
ExifTag: 120
},
Photo: {
ExifVersion: Buffer.from([0x30, 0x32, 0x31, 0x30]),
ComponentsConfiguration: Buffer.from([0x01, 0x02, 0x03, 0x00]),
FlashpixVersion: Buffer.from([0x30, 0x31, 0x30, 0x30]),
ColorSpace: 65535,
PixelXDimension: 1,
PixelYDimension: 1
}
});
});

it('should error when missing Exif tag', function () {
expect(function () {
exif(Buffer.alloc(50));
Expand Down

0 comments on commit 4ca59e2

Please sign in to comment.