Skip to content

Panic if a *.jpg file is actually in fact a PNG file. #2

@pmorch

Description

@pmorch

In my (huge) Google Takeout folder, there was one image, whose filename 20170820-164859.mp4.thumb.jpg implied that was a JPG file, but in fact it was a PNG file.

This is what happens when I run a directory with just that file:

$ ./google-photo-exporter-metadata-fixer/google-photo-exporter-metadata-fixer fix folder 
Found: folder/20170820-164859.mp4.thumb.jpg.json
Processing: folder/20170820-164859.mp4.thumb.jpg.json
Error: runtime error: slice bounds out of range [:1] with capacity 0
Usage:
  google-exporter-metadata-fixer fix [flags]

Flags:
  -d, --deleteJSONFiles   Delete the JSON files after processing
  -h, --help              help for fix

runtime.boundsError runtime error: slice bounds out of range [:1] with capacity 0
/home/peter/go/pkg/mod/github.com/dsoprea/go-jpeg-image-structure/[email protected]/segment_list.go:309 (0x63b68b)
	(*SegmentList).SetExif.func1: err = log.Wrap(state.(error))
/nix/store/gdp1f96y3rhrpncllbngi1chmpc9k0gd-go-1.22.6/share/go/src/runtime/panic.go:770 (0x43b4f2)
	gopanic: fn()
/nix/store/gdp1f96y3rhrpncllbngi1chmpc9k0gd-go-1.22.6/share/go/src/runtime/panic.go:140 (0x43a2bc)
	goPanicSliceAcap: panic(boundsError{x: int64(x), signed: true, y: y, code: boundsSliceAcap})
/home/peter/go/pkg/mod/github.com/dsoprea/go-jpeg-image-structure/[email protected]/segment_list.go:321 (0x63b5c5)
	(*SegmentList).SetExif: prefix := sl.segments[:1]
/home/peter/work/photos/google-photo-exporter-metadata-fixer/internal/metadata_fixer/metadata-fixer.go:276 (0x640cee)
	updatePhotoDateAndEXIF: err = segmentList.SetExif(rootIb)
/home/peter/work/photos/google-photo-exporter-metadata-fixer/internal/metadata_fixer/metadata-fixer.go:98 (0x63f8b8)
	FixPhotoMetadata: err = updatePhotoDateAndEXIF(filepath.Dir(jsonFilePath), result)
/home/peter/work/photos/google-photo-exporter-metadata-fixer/cmd/google-photo-exporter-organizer/root.go:28 (0x6423cb)
	init.0.func1: return metadata_fixer.FixPhotoMetadata(args[0], removeJSONFiles)
/home/peter/go/pkg/mod/github.com/spf13/[email protected]/command.go:940 (0x55b5c2)
	(*Command).execute: if err := c.RunE(c, argWoFlags); err != nil {
/home/peter/go/pkg/mod/github.com/spf13/[email protected]/command.go:1068 (0x55be05)
	(*Command).ExecuteC: err = cmd.execute(flags)
/home/peter/go/pkg/mod/github.com/spf13/[email protected]/command.go:992 (0x64251f)
	(*Command).Execute: _, err := c.ExecuteC()
/home/peter/work/photos/google-photo-exporter-metadata-fixer/cmd/google-photo-exporter-organizer/root.go:18 (0x642513)
	Execute: return rootCmd.Execute()
/home/peter/go/pkg/mod/github.com/spf13/[email protected]/command.go:992 (0x64251a)
	(*Command).Execute: _, err := c.ExecuteC()
/nix/store/gdp1f96y3rhrpncllbngi1chmpc9k0gd-go-1.22.6/share/go/src/runtime/internal/atomic/types.go:194 (0x43ea9d)
	(*Uint32).Load: return Load(&u.value)
/nix/store/gdp1f96y3rhrpncllbngi1chmpc9k0gd-go-1.22.6/share/go/src/runtime/asm_amd64.s:1695 (0x46ea41)
	goexit: BYTE	$0x90	// NOP

And the file is actually a PNG:

$ file folder/20170820-164859.mp4.thumb.jpg
folder/20170820-164859.mp4.thumb.jpg: PNG image data, 96 x 96, 8-bit/color RGB, non-interlaced

So if there is a huge takeout folder, it will run until it encouters this file and then panics, so it doesn't try to continue. Also, the panic starts in a dependency: https://github.com/dsoprea/go-jpeg-image-structure/tree/master/v2 which hasn't seen a commit in 4 years.

Here is the image and JSON file to reproduce this issue.

Image
20170820-164859.mp4.thumb.jpg.json

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions