Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap sharp calls in try/catch to avoid crashing on bad images #28640

Closed
KyleAMathews opened this issue Dec 15, 2020 · 5 comments · Fixed by #28645
Closed

Wrap sharp calls in try/catch to avoid crashing on bad images #28640

KyleAMathews opened this issue Dec 15, 2020 · 5 comments · Fixed by #28645
Labels
good first issue Issue that doesn't require previous experience with Gatsby stale? Issue that may be closed soon due to the original author not responding any more. type: bug An issue or pull request relating to a bug in Gatsby

Comments

@KyleAMathews
Copy link
Contributor

A follow up to #28614

Here are a few other places where sharp reads/writes images that don't seem to have try/catch setup around them.

const pipeline = sharp(file.absolutePath)

const duotoneWithTransparency = await duotoneImage
.joinChannel(percentTransparency, {
raw: { width: info.width, height: info.height, channels: 1 },
})
.raw()
.toBuffer()
return await originalImage
.composite([
{
input: duotoneWithTransparency,
blend: `over`,
raw: { width: info.width, height: info.height, channels: 4 },
},
])
.toBuffer({ resolveWithObject: true })
.then(({ data, info }) =>
sharp(data, {
raw: info,
}).toFormat(format, { ...options })
)

.toBuffer({ resolveWithObject: true })
.then(({ data, info }) => {
for (let i = 0; i < data.length; i = i + info.channels) {
const r = data[i + 0]
const g = data[i + 1]
const b = data[i + 2]
// @see https://en.wikipedia.org/wiki/Relative_luminance
const avg = Math.round(0.2126 * r + 0.7152 * g + 0.0722 * b)
data[i + 0] = duotoneGradient[avg][0]
data[i + 1] = duotoneGradient[avg][1]
data[i + 2] = duotoneGradient[avg][2]
}
return sharp(data, {
raw: info,
}).toFormat(format, { ...options })
})

@KyleAMathews KyleAMathews added the type: bug An issue or pull request relating to a bug in Gatsby label Dec 15, 2020
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Dec 15, 2020
@KyleAMathews KyleAMathews added good first issue Issue that doesn't require previous experience with Gatsby topic: sharp and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Dec 15, 2020
@nategiraudeau
Copy link
Contributor

@KyleAMathews can I work on this?

@KyleAMathews
Copy link
Contributor Author

Please do!

@lesagi
Copy link

lesagi commented Dec 24, 2020

Hi please let me know if you didn't work on that, I'm looking for the first issue for myself :)

@nategiraudeau
Copy link
Contributor

I did. I'm just waiting for the PR to get merged: #28645

@github-actions
Copy link

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here.
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

@github-actions github-actions bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Jan 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Issue that doesn't require previous experience with Gatsby stale? Issue that may be closed soon due to the original author not responding any more. type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants