Commit fd01e328 authored by Robert Sprowson's avatar Robert Sprowson

Flag unrecognised critical tags, but allow ancilliary tags between IDAT and IEND

PNG spec 1.2, section 4.3, turns out tIME iTXt tEXt zTXt have no ordering constraints. Images with these after the IDATs but before IEND were being rejected, plus it's possible to encounter private ancilliary chunks - so it's safest just to let them all through.
Unexpected critical chunks are now explicitly faulted.

Version 1.46. Tagged as 'ChangeFSI-1_46'
parent bd8086c1
/* (1.45)
/* (1.46)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 1.45
#define Module_MajorVersion_CMHG 1.46
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 11 Jan 2014
#define Module_Date_CMHG 15 Jan 2014
#define Module_MajorVersion "1.45"
#define Module_Version 145
#define Module_MajorVersion "1.46"
#define Module_Version 146
#define Module_MinorVersion ""
#define Module_Date "11 Jan 2014"
#define Module_Date "15 Jan 2014"
#define Module_ApplicationDate "11-Jan-14"
#define Module_ApplicationDate "15-Jan-14"
#define Module_ComponentName "ChangeFSI"
#define Module_ComponentPath "mixed/RiscOS/Sources/Apps/ChangeFSI"
#define Module_FullVersion "1.45"
#define Module_HelpVersion "1.45 (11 Jan 2014)"
#define Module_LibraryVersionInfo "1:45"
#define Module_FullVersion "1.46"
#define Module_HelpVersion "1.46 (15 Jan 2014)"
#define Module_LibraryVersionInfo "1:46"
......@@ -585,7 +585,7 @@ load_row ROUT
; Exit
; r0 = V set and error else
; buffer refilled
Push "r0-r6, r8, lr"
Push "r0-r5, r8, lr"
TEQ r0, #0
MOVEQ r0, #2_00010 ; First call
......@@ -606,12 +606,11 @@ load_row ROUT
STMIA r7, { r2-r3, r5 }
CMP r0, #DECOMPRESS_NEED_INPUT
Pull "r0-r6, r8, pc", NE ; Complete
Pull "r0-r5, r8, pc", NE ; Complete
; Need to load some more from the file
LDR r5, [r7, #Wsp_FileBuf]
STR r5, [r7, #Wsp_InBuf] ; Reset input buffer pointer to empty
LDR r6, [sp, #3*4] ; Keep handle handy
20
SUBS r3, r3, #1 ; Re-present trailing bytes
LDRPLB r1, [r2], #1
......@@ -631,7 +630,7 @@ load_row ROUT
MOVCS r8, r1 ; Limit read to data available
MOV r0, #OSGBPB_ReadFromGiven
MOV r1, r6
LDR r1, [sp, #3*4]
MOV r2, r5
MOV r3, r8
LDR r4, [r7, #Wsp_FileOffset]
......@@ -650,9 +649,9 @@ load_row ROUT
STR r4, [r7, #Wsp_FileOffset]
50
; Hunt for the next IDAT
SUB sp, sp, #8
MOV r0, #OSGBPB_ReadFromGiven
MOV r1, r6
LDR r1, [sp, #3*4]
SUB sp, sp, #8
MOV r2, sp
MOV r3, #8
LDR r4, [r7, #Wsp_FileOffset]
......@@ -660,24 +659,33 @@ load_row ROUT
BVS %FT60
LDMIA sp!, { r2-r3 } ; r2 = BE length, r3 = tag
MOV r14, #&FF000000
ORR r14, r14, #&FF00
AND r0, r14, r2, ROR #8 ; ABCD -> DABC -> D.B.
AND r2, r14, r2 ; ABCD -> A.C.
ORR r2, r0, r2, ROR #24 ; -> DCBA endian swapped
LDR r0, load_idat
TEQ r3, r0
BEQ %FT70
LDR r0, load_iend
TEQ r3, r0
BEQ %FT80
TST r3, #1:SHL:5 ; Skip ancilliary tags
ADDNE r4, r4, r2
BNE %BT40
ADR r0, load_duff_err
SETV
60
ADD sp, sp, #4
Pull "r1-r6, r8, pc" ; Fatal
Pull "r1-r5, r8, pc" ; Fatal
70
; It's an IDAT
MOV r3, #&FF000000
ORR r3, r3, #&FF00
AND r0, r3, r2, ROR #8 ; ABCD -> DABC -> D.B.
AND r2, r3, r2 ; ABCD -> A.C.
ORRS r2, r0, r2, ROR #24 ; -> DCBA endian swapped
TEQ r2, #0
BEQ %BT40 ; Skip CRC32 after empty IDAT
STR r2, [r7, #Wsp_FileRem]
......@@ -701,7 +709,7 @@ load_iend
DCB "IEND"
load_duff_err
DCD 42
DCB "Non data tag between IDAT and IEND", 0
DCB "Unrecognised critical tag between IDAT and IEND", 0
ALIGN
zlib_decompress ROUT
......
......@@ -4117,7 +4117,8 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
IF L%<>0 THEN ERROR42, "IEND contains data"
C%=FNbeW:REM Skip CRC32
OTHERWISE
PTR#c%=PTR#c%+L%+4:REM Skip unhandled tags
IF (ASC(t$) AND32)=0 THEN ERROR42, "Unhandled critical tag encountered":REM Not one in PNG spec 1.2
PTR#c%=PTR#c%+L%+4:REM Skip unhandled ancilliary tags
ENDCASE
UNTIL EOF#c%
IF NOT V% THEN ERROR42,"Out of order tag in PNG"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment