Skip to content

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

Merged
esimov merged 1 commit intoesimov:masterfrom
Krzysztofz01:silent-failure-on-invalid-dst-image-type-bug-fix
Apr 30, 2025
Merged

Silent failure on dst image type different than *image.NRGBA#10
esimov merged 1 commit intoesimov:masterfrom
Krzysztofz01:silent-failure-on-invalid-dst-image-type-bug-fix

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