DOC-19: tiff-magic-bytes selbst erkennen (http.DetectContentType kennt tiff nicht)
Test auf 131 zeigte: net/http.DetectContentType hat keinen Sniff-Eintrag fuer TIFF (kein Teil der WHATWG-Sniff-Tabelle), liefert also faelschlich application/octet-stream und der Job schlug fehl. isTIFF() prueft die beiden gueltigen Byte-Order-Signaturen (II*\0 / MM\0*) explizit davor. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ecc23870e3
commit
8ab021199b
1 file changed
+16
@@ -98,6 +98,13 @@ func (g *Generator) process(ctx context.Context, payload jobPayload) error {
|
||||
sniffLen = len(plaintext)
|
||||
}
|
||||
contentType := http.DetectContentType(plaintext[:sniffLen])
|
||||
if isTIFF(plaintext) {
|
||||
// http.DetectContentType kennt image/tiff nicht (kein Eintrag in der
|
||||
// WHATWG-Sniff-Tabelle, die net/http implementiert) - TIFF-Erkennung
|
||||
// bewusst separat ueber die eigene Magic-Byte-Signatur, DetectContentType
|
||||
// liefert dafuer sonst faelschlich application/octet-stream.
|
||||
contentType = "image/tiff"
|
||||
}
|
||||
|
||||
var pngBytes []byte
|
||||
switch {
|
||||
@@ -166,6 +173,15 @@ func (g *Generator) renderPDFFirstPage(pdfBytes []byte) ([]byte, error) {
|
||||
return pngBytes, nil
|
||||
}
|
||||
|
||||
// isTIFF prueft die beiden gueltigen TIFF-Byte-Order-Signaturen (Little- und
|
||||
// Big-Endian, siehe TIFF6-Spezifikation Abschnitt 2).
|
||||
func isTIFF(data []byte) bool {
|
||||
if len(data) < 4 {
|
||||
return false
|
||||
}
|
||||
return bytes.Equal(data[:4], []byte{'I', 'I', 0x2A, 0x00}) || bytes.Equal(data[:4], []byte{'M', 'M', 0x00, 0x2A})
|
||||
}
|
||||
|
||||
// resizeImageToPNG dekodiert ein Bild (JPEG/PNG/GIF/TIFF, bei Multi-Page-TIFF
|
||||
// nur die erste Seite - golang.org/x/image/tiff dekodiert per image.Decode
|
||||
// stets das erste Bild im Container) und verkleinert es
|
||||
|
||||
Reference in new issue
Block a user