From f2030c090bf983556fe36a8cb8062c8aced64e9d Mon Sep 17 00:00:00 2001 From: "Artyom V. Poptsov" Date: Sat, 6 Jan 2024 15:19:14 +0300 Subject: [PATCH] modules/png: Read/write unknown chunk types properly * modules/png/core/chunk.scm (chunk-type->vector): Return the type converted to a bytevector for unknown chunks. * modules/png/fsm/chunk-context.scm (action:store-type): Bugfix: Read unknown chunk types "as is". --- modules/png/core/chunk.scm | 6 +++++- modules/png/fsm/chunk-context.scm | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/modules/png/core/chunk.scm b/modules/png/core/chunk.scm index 8304b31..43ed192 100644 --- a/modules/png/core/chunk.scm +++ b/modules/png/core/chunk.scm @@ -3,6 +3,7 @@ (define-module (png core chunk) #:use-module (oop goops) + #:use-module (ice-9 iconv) #:use-module (png core common) #:use-module (png core crc) #:use-module (srfi srfi-1) @@ -161,7 +162,10 @@ the list." (define-method (chunk-type->vector (type )) "Convert a PNG chunk TYPE to a vector. Return the vector." - (cadr (png-chunk-type-info type))) + (let ((info (png-chunk-type-info type))) + (if info + (cadr (png-chunk-type-info type)) + (string->bytevector (symbol->string type) "ASCII")))) (define-method (png-chunk-type-info (chunk )) (png-chunk-type-info (png-chunk-type chunk))) diff --git a/modules/png/fsm/chunk-context.scm b/modules/png/fsm/chunk-context.scm index 00cecf0..8abfbb6 100644 --- a/modules/png/fsm/chunk-context.scm +++ b/modules/png/fsm/chunk-context.scm @@ -1,5 +1,6 @@ (define-module (png fsm chunk-context) #:use-module (ice-9 binary-ports) + #:use-module (ice-9 iconv) #:use-module (rnrs bytevectors) #:use-module (oop goops) #:use-module (png fsm context) @@ -93,7 +94,15 @@ (action:store ctx byte) (let ((chunk (context-result ctx)) (data (context-buffer ctx))) - (png-chunk-type-set! chunk (car (vector->chunk-type data))) + (let ((type (vector->chunk-type data))) + (if type + (png-chunk-type-set! chunk (car type)) + (let ((type (string->symbol (bytevector->string data "ASCII")))) + (log-warning "action:store-type: Unknown chunk type: ~a (~a)" + data + type) + (png-chunk-type-set! chunk + type)))) (%buffer-reset! ctx (png-chunk-length chunk))) ctx)