lab5: закрытие остаточных замечаний

Validate tRNS semantics and bind PLTE entry count to the IHDR bit depth so malformed PNGs are rejected with 415 instead of failing in the worker. Refuse replay of an older failed version while a newer pipeline job exists, preventing loss of the shared staging source, and retire version-stale queued jobs as superseded instead of republishing them forever.
This commit is contained in:
Vladislav Kunetskiy
2026-10-31 01:46:26 +03:00
parent 624f76b7d0
commit ac30972d48
14 changed files with 357 additions and 33 deletions
+44
View File
@@ -82,7 +82,9 @@ func validatePNG(reader *bufio.Reader, maxPixels int64) (Info, error) {
first = true
hasIDAT bool
paletteReady bool
trnsSeen bool
colorType byte
bitDepth byte
idat bytes.Buffer
raster []pngPass
rasterBytes int64
@@ -166,6 +168,7 @@ func validatePNG(reader *bufio.Reader, maxPixels int64) (Info, error) {
info.Width = int64(binary.BigEndian.Uint32(data[0:4]))
info.Height = int64(binary.BigEndian.Uint32(data[4:8]))
colorType = data[9]
bitDepth = data[8]
if info.Width <= 0 || info.Height <= 0 {
return Info{}, corruptf("png dimensions %dx%d", info.Width, info.Height)
@@ -201,9 +204,50 @@ func validatePNG(reader *bufio.Reader, maxPixels int64) (Info, error) {
return Info{}, corruptf("png PLTE length %d", length)
}
if length/3 > 1<<bitDepth {
return Info{}, corruptf(
"png PLTE has %d entries for bit depth %d", length/3, bitDepth,
)
}
if trnsSeen {
return Info{}, corruptf("png PLTE chunk after tRNS")
}
if !hasIDAT {
paletteReady = true
}
case "tRNS":
if trnsSeen {
return Info{}, corruptf("png duplicate tRNS chunk")
}
if hasIDAT {
return Info{}, corruptf("png tRNS chunk after IDAT")
}
switch colorType {
case 0:
if length != 2 {
return Info{}, corruptf("png tRNS length %d for color type 0", length)
}
case 2:
if length != 6 {
return Info{}, corruptf("png tRNS length %d for color type 2", length)
}
case 3:
if !paletteReady {
return Info{}, corruptf("png tRNS before PLTE")
}
if length > 256 {
return Info{}, corruptf("png tRNS length %d", length)
}
default:
return Info{}, corruptf("png tRNS invalid for color type %d", colorType)
}
trnsSeen = true
case "IEND":
if length != 0 {
return Info{}, corruptf("png IEND length %d", length)