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

Following readme decode example gives errors in imageToRGBA #4

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

Comments

@scottleedavis
Copy link
Contributor

From this file (near copied from readme) https://github.com/scottleedavis/mattermost-plugin-watermark/blob/master/decode.go

func main() {
	inFile, _ := os.Open("./assets/test.jpg") // opening file
	inFile.Close()

	reader := bufio.NewReader(inFile) // buffer reader
	img, _, _ := image.Decode(reader) // decoding to golang's image.Image

	sizeOfMessage := steganography.GetMessageSizeFromImage(img) // retrieving message size to decode in the next line

	msg := steganography.Decode(sizeOfMessage, img) // decoding the message from the file
	fmt.Println(string(msg))
}

gives the following error when run

$ go run decode.go 
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x10b01e7]

goroutine 1 [running]:
gopkg.in/auyer/steganography%2ev2.imageToRGBA(0x0, 0x0, 0x0)
        /Users/scottd/go/pkg/mod/gopkg.in/auyer/[email protected]/steganography.go:339 +0x37
gopkg.in/auyer/steganography%2ev2.decode(0x400000000, 0x0, 0x0, 0x10c3080, 0x1, 0xc0000a8000)
        /Users/scottd/go/pkg/mod/gopkg.in/auyer/[email protected]/steganography.go:202 +0x35
gopkg.in/auyer/steganography%2ev2.GetMessageSizeFromImage(0x0, 0x0, 0x0)
        /Users/scottd/go/pkg/mod/gopkg.in/auyer/[email protected]/steganography.go:237 +0x48
main.main()
        /Users/scottd/workspace/mattermost-plugin-watermark/decode.go:20 +0x195
exit status 2
@auyer
Copy link
Owner

auyer commented Sep 7, 2019

Hi, thanks for looking into this.
There are a few thing to point out:

  1. inFile.Close() cant happen before reader := bufio.NewReader(inFile). I'm updating the readme with a defer in this call.
  2. You should check for errors when running the code for real. This is omitted for brevity in the readme, but maybe I should re-introduce it. This would have caught what I pointed at in 1
  3. I will investigate compatibility issues with jpeg images. For now, try using PNGs when possible.

@scottleedavis
Copy link
Contributor Author

scottleedavis commented Sep 7, 2019

1 & 2 : Done. thank you
3: Excellent! I would really appreciate jpg support as well. I'd be happy to contribute to that as well.

I confirm with the above 1 & 2 changes, png works as intended.

@scottleedavis
Copy link
Contributor Author

scottleedavis commented Sep 7, 2019

In regards to jpg support, reposting a conversation from https://gist.github.com/scottleedavis/25f5e7d1b97dcb8964b74712cfbc6a29 for visibility here.

Screen Shot 2019-09-07 at 3 26 49 PM

jpg test with decode.go, with above approach has this output currently.

$ go run decode.go ./assets/test.jpg 
panic: runtime error: slice bounds out of range

goroutine 1 [running]:
gopkg.in/auyer/steganography%2ev2.decodeRGBA(0xffffffff00000004, 0xc0000b6080, 0xc0000b6080, 0x4, 0x8)
        /Users/scottd/go/pkg/mod/gopkg.in/auyer/[email protected]/steganography.go:180 +0x5a8
gopkg.in/auyer/steganography%2ev2.decode(0xffffffff00000004, 0x1113040, 0xc00014e080, 0xc0000aa000, 0x1113040, 0xc00014e080)
        /Users/scottd/go/pkg/mod/gopkg.in/auyer/[email protected]/steganography.go:203 +0x53
gopkg.in/auyer/steganography%2ev2.Decode(...)
        /Users/scottd/go/pkg/mod/gopkg.in/auyer/[email protected]/steganography.go:217
main.main()
        /Users/scottd/workspace/mattermost-plugin-watermark/decode.go:44 +0x296
exit status 2

@scottleedavis
Copy link
Contributor Author

I believe this is something on my side as I just added jpg unit tests in PR #6

Apologies on the noise, thank you 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