Skip to content

Commit

Permalink
modules/png: Read/write unknown chunk types properly
Browse files Browse the repository at this point in the history
* 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".
  • Loading branch information
artyom-poptsov committed Jan 6, 2024
1 parent f2dab1f commit f2030c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion modules/png/core/chunk.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -161,7 +162,10 @@ the list."

(define-method (chunk-type->vector (type <symbol>))
"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>))
(png-chunk-type-info (png-chunk-type chunk)))
Expand Down
11 changes: 10 additions & 1 deletion modules/png/fsm/chunk-context.scm
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit f2030c0

Please sign in to comment.