]> Cypherpunks repositories - gostls13.git/commitdiff
image/tiff: Reject images with SampleFormat != 1.
authorBenny Siegert <bsiegert@gmail.com>
Fri, 13 May 2011 02:34:48 +0000 (22:34 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 13 May 2011 02:34:48 +0000 (22:34 -0400)
The TIFF spec says that a baseline TIFF reader must gracefully terminate
when the image has a SampleFormat tag which it does not support.
For baseline compatibility, only SampleFormat=1 (the default) is needed.
Images with other sample formats (e.g. floating-point color values)
are very rare in practice.

R=nigeltao
CC=golang-dev
https://golang.org/cl/4515073

src/pkg/image/tiff/consts.go
src/pkg/image/tiff/reader.go

index 761ac9d909451ae277f2ebb880b25b150e76118a..169ba27721d3291c31677fc365c050a5e66dd8d1 100644 (file)
@@ -54,6 +54,7 @@ const (
        tPredictor    = 317
        tColorMap     = 320
        tExtraSamples = 338
+       tSampleFormat = 339
 )
 
 // Compression types (defined in various places in the spec and supplements).
index 40f659c36c8b01658e8f8bf5aee03ce8f81bc934..57a7be4a2575db7082ec1535d5e863a3b0029fd2 100644 (file)
@@ -133,6 +133,20 @@ func (d *decoder) parseIFD(p []byte) os.Error {
                                0xffff,
                        }
                }
+       case tSampleFormat:
+               // Page 27 of the spec: If the SampleFormat is present and
+               // the value is not 1 [= unsigned integer data], a Baseline
+               // TIFF reader that cannot handle the SampleFormat value
+               // must terminate the import process gracefully.
+               val, err := d.ifdUint(p)
+               if err != nil {
+                       return err
+               }
+               for _, v := range val {
+                       if v != 1 {
+                               return UnsupportedError("sample format")
+                       }
+               }
        }
        return nil
 }