Skip to content

Commit 6ff6484

Browse files
committed
Bump icon dimension limits one more time
* Consolidate test into an inline function for reuse * Check detected types and reject the rest... may add to later NOTES: * This is as much as I prefer to go *(may change)*... otherwise the user experience on OUJS will be diminished by excessive bandwidth from client to whatever target. * Ideally these shouldn't be more than 48px by 48px if an author is being nice to their users as well as visitors but do understand some hosting sites kick it up a bit without scaling. Post OpenUserJS#1303
1 parent 5ab4308 commit 6ff6484

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

controllers/scriptStorage.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,15 +1384,34 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
13841384
function (aInnerCallback) {
13851385
// `@icon` validations
13861386
var icon = null;
1387-
var maxX = 128; // px
1388-
var maxY = 128; // px
13891387
var buffer = null;
13901388
var fn = null;
13911389
var dimensions = null;
13921390
var matches = null;
13931391
var data = null;
13941392
var rDataURIbase64 = /^data:image\/.+;base64,(.*)$/;
13951393

1394+
function acceptedImage(aDimensions) {
1395+
var maxX = 256; //px
1396+
var maxY = 256; //px
1397+
1398+
switch (aDimensions.type) {
1399+
case 'gif':
1400+
// fallthrough
1401+
case 'jpeg':
1402+
// fallthrough
1403+
case 'png':
1404+
// fallthrough
1405+
case 'svg':
1406+
// fallthrough
1407+
case 'ico':
1408+
if (dimensions.width <= maxX && dimensions.height <= maxY) {
1409+
return true;
1410+
}
1411+
}
1412+
return false;
1413+
}
1414+
13961415
icon = findMeta(aMeta, 'UserScript.icon.0.value');
13971416
if (icon) {
13981417
if (!isFQUrl(icon, false, true)) {
@@ -1421,9 +1440,9 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
14211440
return;
14221441
}
14231442

1424-
if (dimensions.width > maxX || dimensions.height > maxY) {
1443+
if (!acceptedImage(dimensions)) {
14251444
aInnerCallback(new statusError({
1426-
message: '`@icon` dimensions are too large.',
1445+
message: '`@icon` unsupported file type or dimensions are too large.',
14271446
code: 400
14281447
}), null);
14291448
} else {
@@ -1453,9 +1472,9 @@ exports.storeScript = function (aUser, aMeta, aBuf, aUpdate, aCallback) {
14531472
return;
14541473
}
14551474

1456-
if (dimensions.width > maxX || dimensions.height > maxY) {
1475+
if (!acceptedImage(dimensions)) {
14571476
aInnerCallback(new statusError({
1458-
message: '`@icon` dimensions are too large.',
1477+
message: '`@icon` unsupported file type or dimensions are too large.',
14591478
code: 400
14601479
}), null);
14611480
} else {

0 commit comments

Comments
 (0)