summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2024-11-09 12:56:34 -0500
committerDavid Thompson <dthompson2@worcester.edu>2024-11-09 12:56:34 -0500
commitc19ba72fc241b19423e5dd54b02d7b2f441ced97 (patch)
tree40c045eeb70f856dbe65de134133ae6d350f2567
parent9148240481fd0c13bed3473748a416e21d6c1a70 (diff)
base64: Test for invalid characters when decoding.
-rw-r--r--chickadee/base64.scm10
1 files changed, 7 insertions, 3 deletions
diff --git a/chickadee/base64.scm b/chickadee/base64.scm
index 89fc4bb..c12fa39 100644
--- a/chickadee/base64.scm
+++ b/chickadee/base64.scm
@@ -45,9 +45,9 @@
(let ((cache (make-hash-table)))
(lambda (alphabet)
(or (hash-ref cache alphabet)
- (let ((bv (make-bytevector 128)))
+ (let ((bv (make-bytevector 128 -1)))
(alphabet-for-each (lambda (i x)
- (bytevector-u8-set! bv x i))
+ (bytevector-s8-set! bv x i))
alphabet)
(hash-set! cache alphabet bv)
bv)))))
@@ -56,7 +56,11 @@
"Decode the base64 encoded string @var{str} using @var{alphabet} and
return a bytevector containing the decoded data."
(define decoder (alphabet->decoder alphabet))
- (define (decode char) (bytevector-u8-ref decoder (char->integer char)))
+ (define (decode char)
+ (let ((x (bytevector-s8-ref decoder (char->integer char))))
+ (when (eq? x -1)
+ (error "invalid base64 character" char))
+ x))
(call-with-input-string str
(lambda (in)
(call-with-output-bytevector