Skip to content

Commit 748e8c2

Browse files
committed
Additional error traps for @icon check
* Prevents a server trip on malformed value or missing target with no data with: * Double check that dimensions exist in case the dep fails ``` sh-session RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: ERR_INDEX_OUT_OF_RANGE ``` Post OpenUserJS#1303
1 parent 7d49ebe commit 748e8c2

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

controllers/scriptStorage.js

+20-3
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,14 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
14301430
matches = icon.match(rDataURIbase64);
14311431
if (matches) {
14321432
data = matches[1];
1433+
if (data <= 0) {
1434+
aInnerCallback(new statusError({
1435+
message: '`@icon` has no data',
1436+
code: 400
1437+
}));
1438+
return;
1439+
}
1440+
14331441
buffer = new Buffer(data, 'base64');
14341442
try {
14351443
dimensions = sizeOf(buffer);
@@ -1441,7 +1449,7 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
14411449
return;
14421450
}
14431451

1444-
if (!acceptedImage(dimensions)) {
1452+
if (!dimensions || !acceptedImage(dimensions)) {
14451453
aInnerCallback(new statusError({
14461454
message: '`@icon` unsupported file type or dimensions are too large.',
14471455
code: 400
@@ -1460,7 +1468,7 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
14601468

14611469
// Workaround for #1323
14621470
if (fn === https) {
1463-
aInnerCallback(null); // NOTE: Suspending further checks
1471+
aInnerCallback(null); // NOTE: Suspend further checks
14641472
return;
14651473
}
14661474
// /Workaround for #1323
@@ -1476,6 +1484,15 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
14761484
}
14771485
}).on('end', function () {
14781486
buffer = Buffer.concat(chunks);
1487+
1488+
if (buffer.length <= 0) {
1489+
aInnerCallback(new statusError({
1490+
message: '`@icon` has no data',
1491+
code: 400
1492+
}));
1493+
return;
1494+
}
1495+
14791496
try {
14801497
dimensions = sizeOf(buffer);
14811498
} catch (aE) {
@@ -1486,7 +1503,7 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
14861503
return;
14871504
}
14881505

1489-
if (!acceptedImage(dimensions)) {
1506+
if (!dimensions || !acceptedImage(dimensions)) {
14901507
aInnerCallback(new statusError({
14911508
message: '`@icon` unsupported file type or dimensions are too large.',
14921509
code: 400

0 commit comments

Comments
 (0)