Unverified Commit 39e5570b authored by Steven's avatar Steven Committed by GitHub

fix(next/image): reject empty image on read/write to disk cache (#97278)

parent ae0e0a50
......@@ -1470,5 +1470,7 @@
"1469": "The payload's transport tree is missing a slot that exists in the loader tree: %s",
"1470": "`deflateResumeDataCache` should not be called in edge runtime.",
"1471": "Cannot resolve a dynamic segment that has no param value: the response provides no rendered pathname to parse it from.",
"1472": "Cannot convert a server response with no transport data and no base tree."
"1472": "Cannot convert a server response with no transport data and no base tree.",
"1473": "Invariant: image cache entry \"%s\" is empty",
"1474": "Invariant: cannot write an empty buffer to the image cache"
}
......@@ -188,6 +188,12 @@ async function writeToCacheDir(
etag: string,
upstreamEtag: string
) {
if (buffer.byteLength === 0) {
throw new Error(
'Invariant: cannot write an empty buffer to the image cache'
)
}
const dir = join(/* turbopackIgnore: true */ cacheDir, cacheKey)
const filename = join(
/* turbopackIgnore: true */
......@@ -216,6 +222,9 @@ async function readFromCacheDir(cacheDir: string, cacheKey: string) {
)
const filePath = join(/* turbopackIgnore: true */ dir, file)
const buffer = await promises.readFile(/* turbopackIgnore: true */ filePath)
if (buffer.byteLength === 0) {
throw new Error(`Invariant: image cache entry "${cacheKey}" is empty`)
}
const expireAt = Number(expireAtSt)
const maxAge = Number(maxAgeSt)
return { maxAge, expireAt, etag, upstreamEtag, buffer, extension }
......
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