Skip to content

Commit 8b87fb0

Browse files
authored
Merge pull request #335 from netlify/mk/max-image-size
fix: catch oversize image response
2 parents 27dd4fb + 7ab5aa0 commit 8b87fb0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/lib/templates/imageFunction.js

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ const fetch = require('node-fetch')
44
const imageType = require('image-type')
55
const isSvg = require('is-svg')
66

7+
// 6MB is hard max Lambda response size
8+
const MAX_RESPONSE_SIZE = 6291456
9+
710
function getImageType(buffer) {
811
const type = imageType(buffer)
912
if (type) {
@@ -101,6 +104,13 @@ const handler = async (event) => {
101104
.resize(width)
102105
.toBuffer({ resolveWithObject: true })
103106

107+
if (imageBuffer.length > MAX_RESPONSE_SIZE) {
108+
return {
109+
statusCode: 400,
110+
body: 'Requested image is too large. Maximum size is 6MB.',
111+
}
112+
}
113+
104114
return {
105115
statusCode: 200,
106116
headers: {

0 commit comments

Comments
 (0)