aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNigel Tao <nigeltao@golang.org>2012-09-22 05:55:15 +1000
committerNigel Tao <nigeltao@golang.org>2012-09-22 05:55:15 +1000
commitbff99b63f47cf7f5afba8b6932a7cd19c887e023 (patch)
treed29246c3f24ac46fae5e70f90284e725cfb56b80
parent4ecd79f337b88d77012f5a6796101ab983407390 (diff)
downloadgo-bff99b63f47cf7f5afba8b6932a7cd19c887e023.tar.gz
go-bff99b63f47cf7f5afba8b6932a7cd19c887e023.zip
[release-branch.go1] image/jpeg: ignore an incorrect but harmless trailing restart marker.
««« backport 7af3dbecf445 image/jpeg: ignore an incorrect but harmless trailing restart marker. Fixes #4084. R=r CC=golang-dev https://golang.org/cl/6526043 »»»
-rw-r--r--src/pkg/image/jpeg/reader.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/pkg/image/jpeg/reader.go b/src/pkg/image/jpeg/reader.go
index eb6b0c93b6..8da3611919 100644
--- a/src/pkg/image/jpeg/reader.go
+++ b/src/pkg/image/jpeg/reader.go
@@ -396,6 +396,15 @@ func (d *decoder) decode(r io.Reader, configOnly bool) (image.Image, error) {
if marker == eoiMarker { // End Of Image.
break
}
+ if rst0Marker <= marker && marker <= rst7Marker {
+ // Figures B.2 and B.16 of the specification suggest that restart markers should
+ // only occur between Entropy Coded Segments and not after the final ECS.
+ // However, some encoders may generate incorrect JPEGs with a final restart
+ // marker. That restart marker will be seen here instead of inside the processSOS
+ // method, and is ignored as a harmless error. Restart markers have no extra data,
+ // so we check for this before we read the 16-bit length of the segment.
+ continue
+ }
// Read the 16-bit length of the segment. The value includes the 2 bytes for the
// length itself, so we subtract 2 to get the number of remaining bytes.
@@ -424,7 +433,7 @@ func (d *decoder) decode(r io.Reader, configOnly bool) (image.Image, error) {
err = d.processSOS(n)
case marker == driMarker: // Define Restart Interval.
err = d.processDRI(n)
- case marker >= app0Marker && marker <= app15Marker || marker == comMarker: // APPlication specific, or COMment.
+ case app0Marker <= marker && marker <= app15Marker || marker == comMarker: // APPlication specific, or COMment.
err = d.ignore(n)
default:
err = UnsupportedError("unknown marker")