Unverified Commit b25f7f84 authored by Steven's avatar Steven Committed by GitHub

Fix animated png bypass from Image Optimization API (#35120)

- Fixes #34807
- Related commit https://github.com/qzb/is-animated/commit/69dad3cdf9622cc0bde4ee8c716366b0eef7e627Co-authored-by: 's avatarJJ Kasper <22380829+ijjk@users.noreply.github.com>
parent 0e5e8881
...@@ -116,7 +116,7 @@ ...@@ -116,7 +116,7 @@
"gzip-size": "5.1.1", "gzip-size": "5.1.1",
"html-validator": "5.1.18", "html-validator": "5.1.18",
"image-size": "0.9.3", "image-size": "0.9.3",
"is-animated": "2.0.0", "is-animated": "2.0.2",
"isomorphic-unfetch": "3.0.0", "isomorphic-unfetch": "3.0.0",
"jest": "27.0.6", "jest": "27.0.6",
"ky": "0.19.1", "ky": "0.19.1",
......
(()=>{var e={713:(e,r,t)=>{"use strict";var a=t(641);var i=t(751);var n=t(120);function isAnimated(e){if(a.isGIF(e)){return a.isAnimated(e)}if(i.isPNG(e)){return i.isAnimated(e)}if(n.isWebp(e)){return n.isAnimated(e)}return false}e.exports=isAnimated},641:(e,r)=>{"use strict";function getDataBlocksLength(e,r){var t=0;while(e[r+t]){t+=e[r+t]+1}return t+1}r.isGIF=function(e){var r=e.slice(0,3).toString("ascii");return r==="GIF"};r.isAnimated=function(e){var r,t,a;var i=0;var n=0;a=e.slice(0,3).toString("ascii");if(a!=="GIF"){return false}r=e[10]&128;t=e[10]&7;i+=6;i+=7;i+=r?3*Math.pow(2,t+1):0;while(n<2&&i<e.length){switch(e[i]){case 44:n+=1;r=e[i+9]&128;t=e[i+9]&7;i+=10;i+=r?3*Math.pow(2,t+1):0;i+=getDataBlocksLength(e,i+1)+1;break;case 33:i+=2;i+=getDataBlocksLength(e,i);break;case 59:i=e.length;break;default:i=e.length;break}}return n>1}},751:(e,r)=>{r.isPNG=function(e){var r=e.slice(0,8).toString("hex");return r==="89504e470d0a1a0a"};r.isAnimated=function(e){var r=false;var t=false;var a=false;var i=null;var n=8;while(n<e.length){var s=e.readUInt32BE(n);var u=e.slice(n+4,n+8).toString("ascii");switch(u){case"acTL":r=true;break;case"IDAT":if(!r){return false}if(i!=="fcTL"){return false}t=true;break;case"fdAT":if(!t){return false}if(i!=="fcTL"){return false}a=true;break}i=u;n+=4+4+s+4}return r&&t&&a}},120:(e,r)=>{r.isWebp=function(e){var r=[87,69,66,80];for(var t=0;t<r.length;t++){if(e[t+8]!==r[t]){return false}}return true};r.isAnimated=function(e){var r=[65,78,73,77];for(var t=0;t<e.length;t++){for(var a=0;a<r.length;a++){if(e[t+a]!==r[a]){break}}if(a===r.length){return true}}return false}}};var r={};function __nccwpck_require__(t){var a=r[t];if(a!==undefined){return a.exports}var i=r[t]={exports:{}};var n=true;try{e[t](i,i.exports,__nccwpck_require__);n=false}finally{if(n)delete r[t]}return i.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var t=__nccwpck_require__(713);module.exports=t})(); (()=>{var e={713:(e,r,t)=>{"use strict";var a=t(641);var i=t(751);var n=t(120);function isAnimated(e){if(a.isGIF(e)){return a.isAnimated(e)}if(i.isPNG(e)){return i.isAnimated(e)}if(n.isWebp(e)){return n.isAnimated(e)}return false}e.exports=isAnimated},641:(e,r)=>{"use strict";function getDataBlocksLength(e,r){var t=0;while(e[r+t]){t+=e[r+t]+1}return t+1}r.isGIF=function(e){var r=e.slice(0,3).toString("ascii");return r==="GIF"};r.isAnimated=function(e){var r,t,a;var i=0;var n=0;a=e.slice(0,3).toString("ascii");if(a!=="GIF"){return false}r=e[10]&128;t=e[10]&7;i+=6;i+=7;i+=r?3*Math.pow(2,t+1):0;while(n<2&&i<e.length){switch(e[i]){case 44:n+=1;r=e[i+9]&128;t=e[i+9]&7;i+=10;i+=r?3*Math.pow(2,t+1):0;i+=getDataBlocksLength(e,i+1)+1;break;case 33:i+=2;i+=getDataBlocksLength(e,i);break;case 59:i=e.length;break;default:i=e.length;break}}return n>1}},751:(e,r)=>{r.isPNG=function(e){var r=e.slice(0,8).toString("hex");return r==="89504e470d0a1a0a"};r.isAnimated=function(e){var r=false;var t=false;var a=false;var i=null;var n=8;while(n<e.length){var s=e.readUInt32BE(n);var f=e.slice(n+4,n+8).toString("ascii");switch(f){case"acTL":r=true;break;case"IDAT":if(!r){return false}if(i!=="fcTL"&&i!=="IDAT"){return false}t=true;break;case"fdAT":if(!t){return false}if(i!=="fcTL"&&i!=="fdAT"){return false}a=true;break}i=f;n+=4+4+s+4}return r&&t&&a}},120:(e,r)=>{r.isWebp=function(e){var r=[87,69,66,80];for(var t=0;t<r.length;t++){if(e[t+8]!==r[t]){return false}}return true};r.isAnimated=function(e){var r=[65,78,73,77];for(var t=0;t<e.length;t++){for(var a=0;a<r.length;a++){if(e[t+a]!==r[a]){break}}if(a===r.length){return true}}return false}}};var r={};function __nccwpck_require__(t){var a=r[t];if(a!==undefined){return a.exports}var i=r[t]={exports:{}};var n=true;try{e[t](i,i.exports,__nccwpck_require__);n=false}finally{if(n)delete r[t]}return i.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var t=__nccwpck_require__(713);module.exports=t})();
\ No newline at end of file \ No newline at end of file
...@@ -189,6 +189,22 @@ export function runTests(ctx) { ...@@ -189,6 +189,22 @@ export function runTests(ctx) {
expect(isAnimated(await res.buffer())).toBe(true) expect(isAnimated(await res.buffer())).toBe(true)
}) })
it('should maintain animated png 2', async () => {
const query = { w: ctx.w, q: 90, url: '/animated2.png' }
const res = await fetchViaHTTP(ctx.appPort, '/_next/image', query, {})
expect(res.status).toBe(200)
expect(res.headers.get('content-type')).toContain('image/png')
expect(res.headers.get('Cache-Control')).toBe(
`public, max-age=0, must-revalidate`
)
expect(res.headers.get('Vary')).toBe('Accept')
expect(res.headers.get('etag')).toBeTruthy()
expect(res.headers.get('Content-Disposition')).toBe(
`inline; filename="animated2.png"`
)
expect(isAnimated(await res.buffer())).toBe(true)
})
it('should maintain animated webp', async () => { it('should maintain animated webp', async () => {
const query = { w: ctx.w, q: 90, url: '/animated.webp' } const query = { w: ctx.w, q: 90, url: '/animated.webp' }
const res = await fetchViaHTTP(ctx.appPort, '/_next/image', query, {}) const res = await fetchViaHTTP(ctx.appPort, '/_next/image', query, {})
......
...@@ -12056,10 +12056,10 @@ is-alphanumerical@^1.0.0: ...@@ -12056,10 +12056,10 @@ is-alphanumerical@^1.0.0:
is-alphabetical "^1.0.0" is-alphabetical "^1.0.0"
is-decimal "^1.0.0" is-decimal "^1.0.0"
is-animated@2.0.0: is-animated@2.0.2:
version "2.0.0" version "2.0.2"
resolved "https://registry.yarnpkg.com/is-animated/-/is-animated-2.0.0.tgz#ffb1f180ff10782b8442dcb0955b5fc915e1a111" resolved "https://registry.yarnpkg.com/is-animated/-/is-animated-2.0.2.tgz#579a5d30b0d28c71bfef9dc46ebec969269461ab"
integrity sha512-ZsfhGnSRUjto9owW5WpaDL7z/03H77Ny9JgP/BSyOQ/mAPAKNbdX30WNYbg2R5NhvT5VqKs2KL38znj5OG8tDg== integrity sha512-+Hi3UdXHV/3ZgxdO9Ik45ciNhDlYrDOIdGz7Cj7ybddWnYBi4kwBuGMn79Xa2Js4VldgX5e3943Djsr/KYSPbA==
is-arguments@^1.0.4: is-arguments@^1.0.4:
version "1.0.4" version "1.0.4"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment