diff --git a/ghost/core/core/server/data/importer/import-manager.js b/ghost/core/core/server/data/importer/import-manager.js index 431e5672c5..360c081af7 100644 --- a/ghost/core/core/server/data/importer/import-manager.js +++ b/ghost/core/core/server/data/importer/import-manager.js @@ -235,7 +235,10 @@ class ImportManager { help: tpl(messages.invalidZipFileNameEncodingHelp), code: 'INVALID_ZIP_FILE_NAME_ENCODING' }); - } else if (err.message.includes('end of central directory record signature not found')) { // This comes from Yauzl when the zip is invalid + } else if ( + err.message.includes('end of central directory record signature not found') + || err.message.includes('invalid comment length') + ) { // This comes from Yauzl when the zip is invalid throw new errors.UnsupportedMediaTypeError({ message: tpl(messages.invalidZipFileNameEncoding), code: 'INVALID_ZIP_FILE' diff --git a/ghost/core/test/e2e-api/admin/db.test.js b/ghost/core/test/e2e-api/admin/db.test.js index d439edec4b..9800035799 100644 --- a/ghost/core/test/e2e-api/admin/db.test.js +++ b/ghost/core/test/e2e-api/admin/db.test.js @@ -104,7 +104,7 @@ describe('DB API', function () { }); }); - it('Handles invalid zip file uploads', async function () { + it('Handles invalid zip file uploads (central directory)', async function () { const res = await request.post(localUtils.API.getApiQuery('db/')) .set('Origin', config.get('url')) .attach('importfile', 'test/utils/fixtures/import/zips/empty.zip') @@ -113,4 +113,14 @@ describe('DB API', function () { res.body.errors[0].message.should.eql('The uploaded zip could not be read'); }); + + it('Handles invalid zip file uploads (malformed comments)', async function () { + const res = await request.post(localUtils.API.getApiQuery('db/')) + .set('Origin', config.get('url')) + .attach('importfile', 'test/utils/fixtures/import/zips/malformed-comments.zip') + .expect('Content-Type', /json/) + .expect(415); + + res.body.errors[0].message.should.eql('The uploaded zip could not be read'); + }); }); diff --git a/ghost/core/test/utils/fixtures/import/zips/malformed-comments.zip b/ghost/core/test/utils/fixtures/import/zips/malformed-comments.zip new file mode 100644 index 0000000000..2da0f78d9d Binary files /dev/null and b/ghost/core/test/utils/fixtures/import/zips/malformed-comments.zip differ