Skip to content

Silent failure on dst image type different than *image.NRGBA #10

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

Conversation

Krzysztofz01
Copy link
Contributor

@Krzysztofz01 Krzysztofz01 commented Apr 30, 2025

Hello (it's me again)

I have found one bug that can be difficult to debug, due to its runtime nature and silent failure. Currently, there is no error handling for a case where the dst image is not a *image.NRGBA. A succesfull operation when passing *image.NRGBA as dst and a case when (for example) *image.RGBA is passed as dst can not be distinguished by the return value.

I have added a type validation for the dst image and a comment guiding the developer to provide an image.Image which is a *image.NRGBA internally.

PoC:

func TestPoc(t *testing.T) {
	nrgbaImg := image.NewNRGBA(image.Rect(0, 0, 10, 10))
	rgbaImg := image.NewRGBA(image.Rect(0, 0, 10, 10))

	err := Process(rgbaImg, nrgbaImg, 10)

	if err == nil {
		t.Error("Rgba was used as the destination but no error was returned.")
	}
}

Best regards,
Krzysztof Zoń

@esimov esimov merged commit 7661dcb into esimov:master Apr 30, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants