New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

exif-parser

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

exif-parser - npm Package Compare versions

Comparing version
0.1.4
to
0.1.5
+16
-12
lib/dom-bufferstream.js
/*jslint browser: true, devel: true, bitwise: false, debug: true, eqeq: false, es5: true, evil: false, forin: false, newcap: false, nomen: true, plusplus: true, regexp: false, unparam: false, sloppy: true, stupid: false, sub: false, todo: true, vars: true, white: true */
function DOMBufferStream(arrayBuffer, offset, length, bigEndian, global) {
function DOMBufferStream(arrayBuffer, offset, length, bigEndian, global, parentOffset) {
this.global = global;
this.arrayBuffer = arrayBuffer;
this.offset = offset || 0;
length = length || arrayBuffer.length;
this.endPosition = this.offset + length;
this.view = new global.DataView(arrayBuffer, this.offset, length);
offset = offset || 0;
length = length || (arrayBuffer.byteLength - offset);
this.arrayBuffer = arrayBuffer.slice(offset, offset + length);
this.view = new global.DataView(this.arrayBuffer, 0, this.arrayBuffer.byteLength);
this.setBigEndian(bigEndian);
this.offset = 0;
this.parentOffset = (parentOffset || 0) + offset;
}

@@ -64,3 +65,3 @@

remainingLength: function() {
return this.endPosition - this.offset;
return this.arrayBuffer.byteLength - this.offset;
},

@@ -78,9 +79,12 @@ nextString: function(length) {

offset = (offset || 0) + this.offset;
return new DOMBufferStream(self.arrayBuffer, offset, self.endPosition - offset, self.bigEndian, self.global);
return new DOMBufferStream(self.arrayBuffer, offset, self.arrayBuffer.byteLength - offset, !self.littleEndian, self.global, self.parentOffset);
},
offset: this.offset
offset: this.offset,
getParentOffset: function() {
return self.parentOffset;
}
};
},
offsetFrom: function(marker) {
return this.offset - marker.offset;
return this.parentOffset + this.offset - (marker.offset + marker.getParentOffset());
},

@@ -91,4 +95,4 @@ skip: function(amount) {

branch: function(offset, length) {
length = typeof length === 'number' ? length : this.endPosition - (this.offset + offset);
return new DOMBufferStream(this.arrayBuffer, this.offset + offset, length, this.bigEndian, this.global);
length = typeof length === 'number' ? length : this.arrayBuffer.byteLength - (this.offset + offset);
return new DOMBufferStream(this.arrayBuffer, this.offset + offset, length, !this.littleEndian, this.global, this.parentOffset);
}

@@ -95,0 +99,0 @@ };

@@ -0,1 +1,3 @@

/*jslint browser: true, devel: true, bitwise: false, debug: true, eqeq: false, es5: true, evil: false, forin: false, newcap: false, nomen: true, plusplus: true, regexp: false, unparam: false, sloppy: true, stupid: false, sub: false, todo: true, vars: true, white: true */
function readExifValue(format, stream) {

@@ -84,4 +86,4 @@ switch(format) {

function readIFDSection(tiffMarker, stream, iterator) {
var numberOfEntries = stream.nextUInt16(), tag;
for(var i = 0; i < numberOfEntries; ++i) {
var numberOfEntries = stream.nextUInt16(), tag, i;
for(i = 0; i < numberOfEntries; ++i) {
tag = readExifTag(tiffMarker, stream);

@@ -120,4 +122,8 @@ iterator(tag[0], tag[1], tag[2]);

parseTags: function(stream, iterator) {
var tiffMarker = readHeader(stream);
var tiffMarker;
try {
tiffMarker = readHeader(stream);
} catch(e) {
return false; //ignore APP1 sections with invalid headers
}
var subIfdOffset, gpsOffset, interopOffset;

@@ -159,3 +165,4 @@ var ifd0Stream = tiffMarker.openWithOffset(stream.nextUInt32()),

}
return true;
}
};

@@ -0,1 +1,3 @@

/*jslint browser: true, devel: true, bitwise: false, debug: true, eqeq: false, es5: true, evil: false, forin: false, newcap: false, nomen: true, plusplus: true, regexp: false, unparam: false, sloppy: true, stupid: false, sub: false, todo: true, vars: true, white: true */
module.exports = {

@@ -2,0 +4,0 @@ parseSections: function(stream, iterator) {

@@ -0,1 +1,3 @@

/*jslint browser: true, devel: true, bitwise: false, debug: true, eqeq: false, es5: true, evil: false, forin: false, newcap: false, nomen: true, plusplus: true, regexp: false, unparam: false, sloppy: true, stupid: false, sub: false, todo: true, vars: true, white: true */
var assert = require('assert');

@@ -6,2 +8,54 @@ var jpeg = require('./jpeg'),

function ExifResult(startMarker, tags, imageSize, thumbnailOffset, thumbnailLength, thumbnailType, app1Offset) {
this.startMarker = startMarker;
this.tags = tags;
this.imageSize = imageSize;
this.thumbnailOffset = thumbnailOffset;
this.thumbnailLength = thumbnailLength;
this.thumbnailType = thumbnailType;
this.app1Offset = app1Offset;
}
ExifResult.prototype = {
hasThumbnail: function(mime) {
if(!this.thumbnailOffset || !this.thumbnailLength) {
return false;
}
if(typeof mime !== 'string') {
return true;
}
if(mime.toLowerCase().trim() === 'image/jpeg') {
return this.thumbnailType === 6;
}
if(mime.toLowerCase().trim() === 'image/tiff') {
return this.thumbnailType === 1;
}
return false;
},
getThumbnailOffset: function() {
return this.app1Offset + 6 + this.thumbnailOffset;
},
getThumbnailLength: function() {
return this.thumbnailLength;
},
getThumbnailBuffer: function() {
return this._getThumbnailStream().nextBuffer(this.thumbnailLength);
},
_getThumbnailStream: function() {
return this.startMarker.openWithOffset(this.getThumbnailOffset());
},
getImageSize: function() {
return this.imageSize;
},
getThumbnailSize: function() {
var stream = this._getThumbnailStream(), size;
jpeg.parseSections(stream, function(sectionType, sectionStream) {
if(jpeg.getSectionName(sectionType).name === 'SOF') {
size = jpeg.getSizeFromSOFSection(sectionStream);
}
});
return size;
}
};
function Parser(stream) {

@@ -65,3 +119,3 @@ this.stream = stream;

setTagValue = function(t, value) {
return tags[t.name] = value;
tags[t.name] = value;
};

@@ -71,3 +125,4 @@ } else {

getTagValue = function(t) {
for(var i = 0; i < tags.length; ++i) {
var i;
for(i = 0; i < tags.length; ++i) {
if(tags[i].type === t.type && tags[i].section === t.section) {

@@ -79,3 +134,4 @@ return tags.value;

setTagValue = function(t, value) {
for(var i = 0; i < tags.length; ++i) {
var i;
for(i = 0; i < tags.length; ++i) {
if(tags[i].type === t.type && tags[i].section === t.section) {

@@ -90,5 +146,5 @@ tags.value = value;

jpeg.parseSections(stream, function(sectionType, sectionStream) {
var validExifHeaders, sectionOffset = sectionStream.offsetFrom(start);
if(sectionType === 0xE1) {
app1Offset = sectionStream.offsetFrom(start);
exif.parseTags(sectionStream, function(ifdSection, tagType, value, format) {
validExifHeaders = exif.parseTags(sectionStream, function(ifdSection, tagType, value, format) {
//ignore binary fields if disabled

@@ -101,9 +157,9 @@ if(!flags.readBinaryTags && format === 7) {

thumbnailOffset = value[0];
if(flags.hidePointers) return;
if(flags.hidePointers) {return;}
} else if(tagType === 0x0202) {
thumbnailLength = value[0];
if(flags.hidePointers) return;
if(flags.hidePointers) {return;}
} else if(tagType === 0x0103) {
thumbnailType = value[0];
if(flags.hidePointers) return;
if(flags.hidePointers) {return;}
}

@@ -133,2 +189,8 @@ //if flag is set to not store tags, return here after storing pointers

});
if(validExifHeaders) {
app1Offset = sectionOffset;
console.log('setting app1Offset to ', app1Offset);
} else {
console.log('not setting them');
}
}

@@ -149,54 +211,4 @@ else if(flags.imageSize && jpeg.getSectionName(sectionType).name === 'SOF') {

function ExifResult(startMarker, tags, imageSize, thumbnailOffset, thumbnailLength, thumbnailType, app1Offset) {
this.startMarker = startMarker;
this.tags = tags;
this.imageSize = imageSize;
this.thumbnailOffset = thumbnailOffset;
this.thumbnailLength = thumbnailLength;
this.thumbnailType = thumbnailType;
this.app1Offset = app1Offset;
}
ExifResult.prototype = {
hasThumbnail: function(mime) {
if(!this.thumbnailOffset || !this.thumbnailLength) {
return false;
}
if(typeof mime !== 'string') {
return true;
}
if(mime.toLowerCase().trim() === 'image/jpeg') {
return this.thumbnailType === 6;
}
if(mime.toLowerCase().trim() === 'image/tiff') {
return this.thumbnailType === 1;
}
return false;
},
getThumbnailOffset: function() {
return this.app1Offset + 6 + this.thumbnailOffset;
},
getThumbnailLength: function() {
return this.thumbnailLength;
},
getThumbnailBuffer: function() {
return this._getThumbnailStream().nextBuffer(this.thumbnailLength);
},
_getThumbnailStream: function() {
return this.startMarker.openWithOffset(this.getThumbnailOffset());
},
getImageSize: function() {
return this.imageSize;
},
getThumbnailSize: function() {
var stream = this._getThumbnailStream(), size;
jpeg.parseSections(stream, function(sectionType, sectionStream) {
if(jpeg.getSectionName(sectionType).name === 'SOF') {
size = jpeg.getSizeFromSOFSection(sectionStream);
}
});
return size;
}
};
module.exports = Parser;
{
"name" : "exif-parser",
"version" : "0.1.4",
"version" : "0.1.5",
"description" : "A javascript library to extract Exif metadata from images, in node and in the browser.",

@@ -5,0 +5,0 @@ "author" : "Bruno Windels <bruno.windels@gmail.com>",