aboutsummaryrefslogtreecommitdiff
path: root/pnm/pbm.scm
diff options
context:
space:
mode:
authorMasaya Tojo <masaya@tojo.tokyo>2024-08-04 18:56:16 +0900
committerMasaya Tojo <masaya@tojo.tokyo>2024-08-04 18:56:16 +0900
commitf5d3c117582d25e1aa5b7ea37947653b2276585c (patch)
treea7ecdb71186866bacfd90436c01276bd69fdb6f5 /pnm/pbm.scm
parent5aebc7faba25a31c813b911a3ef253d9bf426bfd (diff)
Check the length of the given bytevector
Diffstat (limited to 'pnm/pbm.scm')
-rw-r--r--pnm/pbm.scm5
1 files changed, 4 insertions, 1 deletions
diff --git a/pnm/pbm.scm b/pnm/pbm.scm
index 32506e0..7e7bc78 100644
--- a/pnm/pbm.scm
+++ b/pnm/pbm.scm
@@ -37,7 +37,8 @@
(data (make-bytevector byte-count 0)))
(make-pbm-image width height data)))
((width height data)
- (let* ((byte-width (ceiling (/ width 8))))
+ (let* ((byte-width (ceiling (/ width 8)))
+ (byte-count (* byte-width height)))
(define (xy->byte-idx+bit-idx x y)
(let-values (((byte-x bit-x) (floor/ x 8)))
(values (+ (* y byte-width)
@@ -52,4 +53,6 @@
(let ((byte (bytevector-u8-ref data byte-idx)))
(bytevector-u8-set! data byte-idx
(copy-bit (- 7 bit-idx) byte b)))))
+ (unless (= byte-count (bytevector-length data))
+ (error (string-append "(pnm pbm) make-pbm-image: Invalid bytevector length" byte-count)))
(make-image 'pbm width height 1 data pixel-getter pixel-setter)))))))