ActivityPub-federated video streaming platform using P2P directly in your web browser
Fix infinite loop with some gif files
Chocobozzz117179e198e6
diff --git a/packages/tests/fixtures/animated-many-frames.gif b/packages/tests/fixtures/animated-many-frames.gifnew file mode 100644index 0000000000..d09c68e9dcBinary files /dev/null and b/packages/tests/fixtures/animated-many-frames.gif differdiff --git a/packages/tests/fixtures/animated-many-frames.webp b/packages/tests/fixtures/animated-many-frames.webpnew file mode 100644index 0000000000..08877c75a0Binary files /dev/null and b/packages/tests/fixtures/animated-many-frames.webp differdiff --git a/packages/tests/fixtures/animated.gif b/packages/tests/fixtures/animated.gifnew file mode 100644index 0000000000..138de2dca4Binary files /dev/null and b/packages/tests/fixtures/animated.gif differdiff --git a/packages/tests/fixtures/animated.webp b/packages/tests/fixtures/animated.webpnew file mode 100644index 0000000000..6715112e16Binary files /dev/null and b/packages/tests/fixtures/animated.webp differdiff --git a/packages/tests/src/server-helpers/image.ts b/packages/tests/src/server-helpers/image.tsindex 140ecf1af1..8f3891ff90 100644--- a/packages/tests/src/server-helpers/image.ts+++ b/packages/tests/src/server-helpers/image.ts@@ -1,12 +1,13 @@/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */+import { buildAbsoluteFixturePath, root } from '@peertube/peertube-node-utils'+import { execPromise } from '@peertube/peertube-server/core/helpers/core-utils.js'+import { processImage } from '@peertube/peertube-server/core/helpers/image-utils.js'import { expect } from 'chai'import { remove } from 'fs-extra/esm'import { readFile } from 'fs/promises'import { join } from 'path'-import { buildAbsoluteFixturePath, root } from '@peertube/peertube-node-utils'-import { execPromise } from '@peertube/peertube-server/core/helpers/core-utils.js'-import { processImage } from '@peertube/peertube-server/core/helpers/image-utils.js'+import sharp from 'sharp'async function checkBuffers (path1: string, path2: string, equals: boolean) {const [ buf1, buf2 ] = await Promise.all([@@ -84,6 +85,38 @@ describe('Image helpers', function () {expect(await hasTitleExif(imageDestPNG)).to.be.false})+ it('Should process animated gif', async function () {+ const ext = '.gif'++ const input = buildAbsoluteFixturePath(`animated${ext}`)++ const dest = join(imageDestDir, `animated${ext}`)+ await processImage({ path: input, destination: dest, newSize: thumbnailSize, keepOriginal: true })++ const inputBuffer = await readFile(dest)++ const sharpInstance = sharp(inputBuffer, { animated: true })+ const metadata = await sharpInstance.metadata()++ expect(metadata.pages).to.equal(25)+ })++ it('Should not process animated gif/webp with too many frames', async function () {+ const ext = '.gif'++ const input = buildAbsoluteFixturePath(`animated-many-frames${ext}`)++ const dest = join(imageDestDir, `animated-many-frames${ext}`)+ await processImage({ path: input, destination: dest, newSize: thumbnailSize, keepOriginal: true })++ const inputBuffer = await readFile(dest)++ const sharpInstance = sharp(inputBuffer, { animated: true })+ const metadata = await sharpInstance.metadata()++ expect(metadata.pages).to.equal(1)+ })+after(async function () {await remove(imageDestDir)})diff --git a/server/core/helpers/image-utils.ts b/server/core/helpers/image-utils.tsindex f84ed0be59..b42476e650 100644--- a/server/core/helpers/image-utils.ts+++ b/server/core/helpers/image-utils.ts@@ -80,7 +80,7 @@ async function sharpProcessor (options: {const metadata = await sharpInstance.metadata()- if (metadata.pages > 200) {+ if (animated && metadata.pages > 200) {logger.info('Too much frames in animated image ' + path + ', skipping animation')return sharpProcessor({ ...options, animated: false })