We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Thank you for an useful package. I've noticed something weird during making an application that edit Exif data of images, so let me share.
If I parse and write the same file repeatedly, it makes an EOF error in ConstructExifBuilder. It happens even if I do not make any change on the file.
I guess that SegmentList.SetExif creates broken data, and Parser cannot handle it correctly.
Thank you.
Here is an example code:
func panicIf(err error) { if err != nil { panic(err) } } func main() { original, err := os.ReadFile("test.jpg") panicIf(err) buf := bytes.NewBuffer(original) for i := 0; i <= 10; i++ { fmt.Println("\nAttempt:", i) jmp := jpegstructure.NewJpegMediaParser() ec, err := jmp.ParseBytes(buf.Bytes()) panicIf(err) sl := ec.(*jpegstructure.SegmentList) sl.Print() root, err := sl.ConstructExifBuilder() panicIf(err) err = sl.SetExif(root) panicIf(err) buf.Reset() err = sl.Write(buf) panicIf(err) } }
Output:
Attempt: 0 0: OFFSET=(0x00000000 0) ID=(0xd8) NAME=[SOI ] SIZE=( 0) SHA1=[da39a3ee5e6b4b0d3255bfef95601890afd80709] 1: OFFSET=(0x00000002 2) ID=(0xe0) NAME=[APP0 ] SIZE=( 14) SHA1=[fddf3ec343286b4c4f0b53216edecc99127c7801] 2: OFFSET=(0x00000014 20) ID=(0xe1) NAME=[APP1 ] SIZE=( 1276) SHA1=[3d33430474752e20a2197b8c26b579fee3b08053] [EXIF] 3: OFFSET=(0x00000514 1300) ID=(0xe1) NAME=[APP1 ] SIZE=( 9446) SHA1=[885d7773b99c212f216272252b1c543805096118] [XMP] 4: OFFSET=(0x000029fe 10750) ID=(0xe2) NAME=[APP2 ] SIZE=( 9026) SHA1=[40a8af678466b122ee88d10f8e181ce4c49e923e] 5: OFFSET=(0x00004d44 19780) ID=(0xdb) NAME=[DQT ] SIZE=( 65) SHA1=[012148c61990b281570800a5761ed4bf7ce642f7] 6: OFFSET=(0x00004d89 19849) ID=(0xdb) NAME=[DQT ] SIZE=( 65) SHA1=[e38b62514186b5ab86cca51bc5f89d7fd26411da] 7: OFFSET=(0x00004dce 19918) ID=(0xc0) NAME=[SOF0 ] SIZE=( 15) SHA1=[067aaf5cb11b8554c8c93d8c1a53e6d7a40b1808] 8: OFFSET=(0x00004de1 19937) ID=(0xc4) NAME=[DHT ] SIZE=( 26) SHA1=[c50d6ac224f040c5b76a7c5bbbaa81919ab7919b] 9: OFFSET=(0x00004dff 19967) ID=(0xc4) NAME=[DHT ] SIZE=( 79) SHA1=[7a2a58ebcb31904909912789c8d57d5d10df100a] 10: OFFSET=(0x00004e52 20050) ID=(0xc4) NAME=[DHT ] SIZE=( 25) SHA1=[50e9f498b3b5990ae80bace38be4abb5fc1b3b2f] 11: OFFSET=(0x00004e6f 20079) ID=(0xc4) NAME=[DHT ] SIZE=( 56) SHA1=[99ed61ecc51ffee506a0ca0510ebc95be9450ac7] 12: OFFSET=(0x00004eab 20139) ID=(0xda) NAME=[SOS ] SIZE=( 0) SHA1=[da39a3ee5e6b4b0d3255bfef95601890afd80709] 13: OFFSET=(0x00004ead 20141) ID=(0x00) NAME=[ ] SIZE=( 3041996) SHA1=[0fb553ddda6b4a4788bfef870e7fbb3ef7adf4c8] 14: OFFSET=(0x002eb979 3062137) ID=(0xd9) NAME=[EOI ] SIZE=( 0) SHA1=[da39a3ee5e6b4b0d3255bfef95601890afd80709] Attempt: 1 0: OFFSET=(0x00000000 0) ID=(0xd8) NAME=[SOI ] SIZE=( 0) SHA1=[da39a3ee5e6b4b0d3255bfef95601890afd80709] 1: OFFSET=(0x00000002 2) ID=(0xe0) NAME=[APP0 ] SIZE=( 14) SHA1=[fddf3ec343286b4c4f0b53216edecc99127c7801] 2: OFFSET=(0x00000014 20) ID=(0xe1) NAME=[APP1 ] SIZE=( 1153) SHA1=[316f432f2b616661d285977940fa6668e8cd5241] [EXIF] 3: OFFSET=(0x00000499 1177) ID=(0xe1) NAME=[APP1 ] SIZE=( 9446) SHA1=[885d7773b99c212f216272252b1c543805096118] [XMP] 4: OFFSET=(0x00002983 10627) ID=(0xe2) NAME=[APP2 ] SIZE=( 9026) SHA1=[40a8af678466b122ee88d10f8e181ce4c49e923e] 5: OFFSET=(0x00004cc9 19657) ID=(0xdb) NAME=[DQT ] SIZE=( 65) SHA1=[012148c61990b281570800a5761ed4bf7ce642f7] 6: OFFSET=(0x00004d0e 19726) ID=(0xdb) NAME=[DQT ] SIZE=( 65) SHA1=[e38b62514186b5ab86cca51bc5f89d7fd26411da] 7: OFFSET=(0x00004d53 19795) ID=(0xc0) NAME=[SOF0 ] SIZE=( 15) SHA1=[067aaf5cb11b8554c8c93d8c1a53e6d7a40b1808] 8: OFFSET=(0x00004d66 19814) ID=(0xc4) NAME=[DHT ] SIZE=( 26) SHA1=[c50d6ac224f040c5b76a7c5bbbaa81919ab7919b] 9: OFFSET=(0x00004d84 19844) ID=(0xc4) NAME=[DHT ] SIZE=( 79) SHA1=[7a2a58ebcb31904909912789c8d57d5d10df100a] 10: OFFSET=(0x00004dd7 19927) ID=(0xc4) NAME=[DHT ] SIZE=( 25) SHA1=[50e9f498b3b5990ae80bace38be4abb5fc1b3b2f] 11: OFFSET=(0x00004df4 19956) ID=(0xc4) NAME=[DHT ] SIZE=( 56) SHA1=[99ed61ecc51ffee506a0ca0510ebc95be9450ac7] 12: OFFSET=(0x00004e30 20016) ID=(0xda) NAME=[SOS ] SIZE=( 0) SHA1=[da39a3ee5e6b4b0d3255bfef95601890afd80709] 13: OFFSET=(0x00004e32 20018) ID=(0x00) NAME=[ ] SIZE=( 3041996) SHA1=[0fb553ddda6b4a4788bfef870e7fbb3ef7adf4c8] 14: OFFSET=(0x002eb8fe 3062014) ID=(0xd9) NAME=[EOI ] SIZE=( 0) SHA1=[da39a3ee5e6b4b0d3255bfef95601890afd80709] Attempt: 2 0: OFFSET=(0x00000000 0) ID=(0xd8) NAME=[SOI ] SIZE=( 0) SHA1=[da39a3ee5e6b4b0d3255bfef95601890afd80709] 1: OFFSET=(0x00000002 2) ID=(0xe0) NAME=[APP0 ] SIZE=( 14) SHA1=[fddf3ec343286b4c4f0b53216edecc99127c7801] 2: OFFSET=(0x00000014 20) ID=(0xe1) NAME=[APP1 ] SIZE=( 1153) SHA1=[c20699191927ea071bf4775fa7bf69bd5bb87bab] [EXIF] 3: OFFSET=(0x00000499 1177) ID=(0xe1) NAME=[APP1 ] SIZE=( 9446) SHA1=[885d7773b99c212f216272252b1c543805096118] [XMP] 4: OFFSET=(0x00002983 10627) ID=(0xe2) NAME=[APP2 ] SIZE=( 9026) SHA1=[40a8af678466b122ee88d10f8e181ce4c49e923e] 5: OFFSET=(0x00004cc9 19657) ID=(0xdb) NAME=[DQT ] SIZE=( 65) SHA1=[012148c61990b281570800a5761ed4bf7ce642f7] 6: OFFSET=(0x00004d0e 19726) ID=(0xdb) NAME=[DQT ] SIZE=( 65) SHA1=[e38b62514186b5ab86cca51bc5f89d7fd26411da] 7: OFFSET=(0x00004d53 19795) ID=(0xc0) NAME=[SOF0 ] SIZE=( 15) SHA1=[067aaf5cb11b8554c8c93d8c1a53e6d7a40b1808] 8: OFFSET=(0x00004d66 19814) ID=(0xc4) NAME=[DHT ] SIZE=( 26) SHA1=[c50d6ac224f040c5b76a7c5bbbaa81919ab7919b] 9: OFFSET=(0x00004d84 19844) ID=(0xc4) NAME=[DHT ] SIZE=( 79) SHA1=[7a2a58ebcb31904909912789c8d57d5d10df100a] 10: OFFSET=(0x00004dd7 19927) ID=(0xc4) NAME=[DHT ] SIZE=( 25) SHA1=[50e9f498b3b5990ae80bace38be4abb5fc1b3b2f] 11: OFFSET=(0x00004df4 19956) ID=(0xc4) NAME=[DHT ] SIZE=( 56) SHA1=[99ed61ecc51ffee506a0ca0510ebc95be9450ac7] 12: OFFSET=(0x00004e30 20016) ID=(0xda) NAME=[SOS ] SIZE=( 0) SHA1=[da39a3ee5e6b4b0d3255bfef95601890afd80709] 13: OFFSET=(0x00004e32 20018) ID=(0x00) NAME=[ ] SIZE=( 3041996) SHA1=[0fb553ddda6b4a4788bfef870e7fbb3ef7adf4c8] 14: OFFSET=(0x002eb8fe 3062014) ID=(0xd9) NAME=[EOI ] SIZE=( 0) SHA1=[da39a3ee5e6b4b0d3255bfef95601890afd80709] panic: EOF goroutine 1 [running]: main.panicIf(...) /mnt/tmpfs/tea/main.go:13 main.main() /mnt/tmpfs/tea/main.go:35 +0x1f8 exit status 2
My environment is:
$ go version go version go1.21.5 linux/amd64 $ cat go.mod module test go 1.21.5 require github.com/dsoprea/go-jpeg-image-structure/v2 v2.0.0-20221012074422-4f3f7e934102 require ( github.com/dsoprea/go-exif/v3 v3.0.1 // indirect github.com/dsoprea/go-iptc v0.0.0-20200609062250-162ae6b44feb // indirect github.com/dsoprea/go-logging v0.0.0-20200710184922-b02d349568dd // indirect github.com/dsoprea/go-photoshop-info-format v0.0.0-20200609050348-3db9b63b202c // indirect github.com/dsoprea/go-utility/v2 v2.0.0-20221003172846-a3e1774ef349 // indirect github.com/go-errors/errors v1.4.2 // indirect github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b // indirect github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 // indirect golang.org/x/net v0.0.0-20221002022538-bcab6841153b // indirect gopkg.in/yaml.v2 v2.4.0 // indirect )
The code was successfully done if I remove following lines, so these methods can be the problem.
root, err := sl.ConstructExifBuilder() panicIf(err) err = sl.SetExif(root) panicIf(err)
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Thank you for an useful package.
I've noticed something weird during making an application that edit Exif data of images, so let me share.
If I parse and write the same file repeatedly, it makes an EOF error in ConstructExifBuilder.
It happens even if I do not make any change on the file.
I guess that SegmentList.SetExif creates broken data, and Parser cannot handle it correctly.
Thank you.
Here is an example code:
Output:
My environment is:
$ go version go version go1.21.5 linux/amd64 $ cat go.mod module test go 1.21.5 require github.com/dsoprea/go-jpeg-image-structure/v2 v2.0.0-20221012074422-4f3f7e934102 require ( github.com/dsoprea/go-exif/v3 v3.0.1 // indirect github.com/dsoprea/go-iptc v0.0.0-20200609062250-162ae6b44feb // indirect github.com/dsoprea/go-logging v0.0.0-20200710184922-b02d349568dd // indirect github.com/dsoprea/go-photoshop-info-format v0.0.0-20200609050348-3db9b63b202c // indirect github.com/dsoprea/go-utility/v2 v2.0.0-20221003172846-a3e1774ef349 // indirect github.com/go-errors/errors v1.4.2 // indirect github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b // indirect github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 // indirect golang.org/x/net v0.0.0-20221002022538-bcab6841153b // indirect gopkg.in/yaml.v2 v2.4.0 // indirect )
The code was successfully done if I remove following lines, so these methods can be the problem.
The text was updated successfully, but these errors were encountered: