0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Fixed error when requesting resize of a blank image

closes https://github.com/TryGhost/Team/issues/819

- adds guard for an empty buffer when reading file from storage for resizing, if a blank image is loaded then redirect to the original file
This commit is contained in:
Kevin Ansfield 2021-07-07 19:11:19 +01:00 committed by Fabien 'egg' O'Carroll
parent d36ee59dbe
commit 54b537deba

View file

@ -1,5 +1,6 @@
const _ = require('lodash');
const path = require('path');
const {GhostError} = require('@tryghost/errors');
const imageTransform = require('@tryghost/image-transform');
const storage = require('../../../adapters/storage');
const activeTheme = require('../../../../frontend/services/themes/active');
@ -100,6 +101,12 @@ module.exports = function (req, res, next) {
return storageInstance.read({path: storagePath});
})
.then((originalImageBuffer) => {
if (originalImageBuffer.length <= 0) {
throw new GhostError({
errorType: 'NoContentError',
statusCode: 204
});
}
return imageTransform.resizeFromBuffer(originalImageBuffer, imageDimensionConfig);
})
.then((resizedImageBuffer) => {
@ -108,7 +115,7 @@ module.exports = function (req, res, next) {
}).then(() => {
next();
}).catch(function (err) {
if (err.code === 'SHARP_INSTALLATION') {
if (err.code === 'SHARP_INSTALLATION' || err.errorType === 'NoContentError') {
return redirectToOriginal();
}
next(err);