probe-image-size
Advanced tools
Comparing version 7.2.1 to 7.2.2
@@ -40,3 +40,8 @@ 'use strict'; | ||
stream.on('redirect', function (location) { | ||
finalUrl = new URL(location, finalUrl).href; | ||
try { | ||
finalUrl = new URL(location, finalUrl).href; | ||
} catch (err) { | ||
reject(err); | ||
stream.request.abort(); | ||
} | ||
}); | ||
@@ -43,0 +48,0 @@ |
@@ -47,7 +47,17 @@ 'use strict'; | ||
function parseJpegMarker(parser, callback) { | ||
function parseJpegMarker(parser, sandbox, callback) { | ||
var start = sandbox.start; | ||
sandbox.start = false; | ||
parser._bytes(1, function (data) { | ||
if (data[0] !== 0xFF) { | ||
// not a JPEG marker | ||
callback(); | ||
if (start) { | ||
// expect JPEG file to start with `FFD8 FFE0`, `FFD8 FFE2` or `FFD8 FFE1`, | ||
// don't allow garbage before second marker | ||
callback(); | ||
} else { | ||
// skip until we see 0xFF, see https://github.com/nodeca/probe-image-size/issues/68 | ||
parseJpegMarker(parser, sandbox, callback); | ||
} | ||
return; | ||
@@ -63,3 +73,3 @@ } | ||
function getJpegSize(parser, sandbox) { | ||
parseJpegMarker(parser, function (code, length) { | ||
parseJpegMarker(parser, sandbox, function (code, length) { | ||
if (!code || length < 0) { | ||
@@ -139,3 +149,3 @@ // invalid jpeg | ||
getJpegSize(parser, {}); | ||
getJpegSize(parser, { start: true }); | ||
}); | ||
@@ -142,0 +152,0 @@ |
@@ -17,4 +17,5 @@ 'use strict'; | ||
// first marker of the file MUST be 0xFFD8 | ||
if (data[0] !== 0xFF || data[1] !== 0xD8) return; | ||
// first marker of the file MUST be 0xFFD8, | ||
// following by either 0xFFE0, 0xFFE2 or 0xFFE3 | ||
if (data[0] !== 0xFF || data[1] !== 0xD8 || data[2] !== 0xFF) return; | ||
@@ -24,5 +25,7 @@ var offset = 2; | ||
for (;;) { | ||
if (data.length - offset < 2) return; | ||
// not a JPEG marker | ||
if (data[offset++] !== 0xFF) return; | ||
// skip until we see 0xFF, see https://github.com/nodeca/probe-image-size/issues/68 | ||
for (;;) { | ||
if (data.length - offset < 2) return; | ||
if (data[offset++] === 0xFF) break; | ||
} | ||
@@ -29,0 +32,0 @@ var code = data[offset++]; |
{ | ||
"name": "probe-image-size", | ||
"version": "7.2.1", | ||
"version": "7.2.2", | ||
"description": "Get image size without full download (JPG, GIF, PNG, WebP, BMP, TIFF, PSD)", | ||
@@ -43,6 +43,6 @@ "keywords": [ | ||
"devDependencies": { | ||
"eslint": "^7.12.1", | ||
"mocha": "^8.2.0", | ||
"eslint": "^8.2.0", | ||
"mocha": "^9.1.3", | ||
"nyc": "^15.1.0" | ||
} | ||
} |
@@ -16,2 +16,3 @@ probe-image-size | ||
- effective with big images (speed/memory), download minimal data from remotes | ||
- extracts orientation value when available | ||
- easy to browserify (splitted to components) | ||
@@ -18,0 +19,0 @@ |
1977
139
70078
32