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

Encode & decode in same memory/execution produce empty message output #5

Closed
scottleedavis opened this issue Sep 7, 2019 · 3 comments

Comments

@scottleedavis
Copy link
Contributor

During troubleshooting a failing test where this library is called by a plugin:
https://github.com/scottleedavis/mattermost-plugin-watermark/blob/master/server/plugin_test.go#L69-L78
I found what appears to be a bug where calling Encode & Decode during the same memory/execution of a program, produces an empty message. However, when an encode happens separately from a decode, everything seems to work as intended. (In my case running Encode via plugin inside mattermost, and later downloading the image and running Decode)

Two examples that fail on my system.

If there any glaring errors in any of the above code, please let me know!

Thank you for building this library! 👍

@auyer
Copy link
Owner

auyer commented Sep 7, 2019

I ran and commented on both your gists. Go check them out!

Encoding and decoding happens in one single test in this package, and there is no reason it should not work elsewhere.
Give this Test a look:

func TestEncodeDecodeGeneratedSmallImage(t *testing.T) {
// Creating image
width := 30
height := 1
upLeft := image.Point{0, 0}
lowRight := image.Point{width, height}
newimg := image.NewRGBA(image.Rectangle{upLeft, lowRight})
// Set color for each pixel.
for x := 0; x < width; x++ {
for y := 0; y < height; y++ {
newimg.Set(x, y, color.White)
}
}
w := new(bytes.Buffer)
err := EncodeRGBA(w, newimg, []uint8{84, 84, 84}) // Encode the message into the image file
if err != nil {
log.Printf("Error Encoding file %v", err)
t.FailNow()
}
decodeImg, _, err := image.Decode(w)
if err != nil {
log.Println("Failed to Decode Image")
t.FailNow()
}
sizeOfMessage := GetMessageSizeFromImage(decodeImg)
msg := Decode(sizeOfMessage, decodeImg) // Read the message from the picture file
// otherwise, print the message to STDOUT
if !bytes.Equal(msg, []uint8{84, 84, 84}) {
log.Println(string(msg))
log.Print("messages dont match")
t.FailNow()
}
}

@scottleedavis
Copy link
Contributor Author

Cool, thank you for the test reference.

Could anything in my environment be affecting this perhaps?

$ go version
go version go1.12.5 darwin/amd64

@scottleedavis
Copy link
Contributor Author

it appears, the png I was testing against was corrupted. I can say every test/setup discussed works now, except the unit test for the plugin.

If you have desire you are welcome to check it out or contribute, however no pressure at all.

scottleedavis/mattermost-plugin-watermark#2
make test runs the test

Thanks for your help!

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

No branches or pull requests

2 participants