Skip to content

image/jpeg: EOF error when decoding image file instead of ErrUnexpectedEOF  #56724

@cupperservice

Description

@cupperservice

What version of Go are you using (go version)?

$ go version
go version go1.19.3 darwin/arm64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/kawashima-kazuh/Library/Caches/go-build"
GOENV="/Users/kawashima-kazuh/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/kawashima-kazuh/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/kawashima-kazuh/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.19.3/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.19.3/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.19.3"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/kawashima-kazuh/Library/CloudStorage/OneDrive-Cybozu/Yakumo/YLOG-4247(Vermeerで発生するEOFの発生箇所を調査する)/image-test/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/gf/q85z6yx574d7vt8p39gxgmq40000gp/T/go-build1027907948=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Here is a sample code to reproduce an EOF error:

package main

import(
	"io"
	"os"
	"github.com/pkg/errors"
	"fmt"
	"image"
	"log"
	_ "image/jpeg"
)

func main() {
	f := os.Stdin
	defer f.Close()

	_, err := loadImage(f)
	if err != nil {
		log.Fatalf("can not load image %v", err)
	}
}

func loadImage(reader io.Reader) (image.Image, error) {
	fmt.Println("load image")
	img, _, err := image.Decode(reader)
	if err != nil {
		return nil, errors.WithStack(err)
	}
	return img, err
}

EOF error occurs when processing the first 24 bytes of the attachment file with the sample code.

head -c24 1x1.jpg | go run main.go

What did you expect to see?

I want to return ErrUnexpectedEOF if err is EOF as follows

if err := d.fill(); err != nil {
	if err == io.EOF {
		err = io.ErrUnexpectedEOF
	}
	return err
}

What did you see instead?

image.Decode returned an EOF error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions