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

image/jpeg: "bad RST marker" error when decoding #40130

Open
haoyang-zheng opened this issue Jul 9, 2020 · 2 comments · May be fixed by #41875
Open

image/jpeg: "bad RST marker" error when decoding #40130

haoyang-zheng opened this issue Jul 9, 2020 · 2 comments · May be fixed by #41875

Comments

@haoyang-zheng
Copy link

@haoyang-zheng haoyang-zheng commented Jul 9, 2020

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

$ go version
go version go1.14.4 darwin/amd64

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="amd64"
GOBIN=""
GOCACHE="/Users/teikouyou/Library/Caches/go-build"
GOENV="/Users/teikouyou/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/teikouyou/dev/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14.4/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14.4/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/d7/wlm33f9550x_3bzzp_3b32h40000gn/T/go-build574141687=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

The following error occurred when I decoded a specific image.

invalid JPEG format: bad RST marker

Part of binary data of the image

ff ff ff ff ff ff ff ff ff ff ff ff d0 fd 32 4b

The correct marker here should be [ ff d0 ], but there is some ff bytes in front of it.

It seems that there is a consecutive 0xFF bytes in the SOS segment that causes problems in marker's matching.

This is a quote from jpeg Wikipedia.
https://en.wikipedia.org/wiki/JPEG#Syntax_and_structure

Note that consecutive 0xFF bytes are used as fill bytes for padding purposes, although this fill byte padding should only ever take place for markers immediately following entropy-coded scan data (see JPEG specification section B.1.1.2 and E.1.2 for details; specifically "In all cases where markers are appended after the compressed data, optional 0xFF fill bytes may precede the marker"

So I think this situation should be taken into account at image/jpeg/scan.go

if d.tmp[0] != 0xff || d.tmp[1] != expectedRST {

What did you expect to see?

Image successfully decoded

What did you see instead?

invalid JPEG format: bad RST marker

@dmitshur dmitshur changed the title image jpeg error when decoding : bad RST marker image/jpeg: "bad RST marker" error when decoding Jul 10, 2020
@dmitshur dmitshur added this to the Backlog milestone Jul 10, 2020
@dmitshur
Copy link
Contributor

@dmitshur dmitshur commented Jul 10, 2020

Loading

@shouldend shouldend linked a pull request that will close this issue Oct 9, 2020
@gopherbot
Copy link

@gopherbot gopherbot commented Oct 9, 2020

Change https://golang.org/cl/260837 mentions this issue: image/jpeg: skip consecutive 0xff bytes

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants