unbase64 skips over *any* illegal chars
authorJorge Chamorro Bieling <jorge@jorgechamorro.com>
Mon, 18 Oct 2010 20:08:42 +0000 (22:08 +0200)
committerRyan Dahl <ry@tinyclouds.org>
Mon, 18 Oct 2010 22:22:10 +0000 (15:22 -0700)
src/node_buffer.cc
test/simple/test-buffer.js

index 3f254081f5eac225df9257e091f906144ec9f30c..bc9ef0426a231d35d29bf614eb64f8b66b2cba4a 100644 (file)
@@ -230,8 +230,16 @@ static const int unbase64_table[] =
   ,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1
   ,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40
   ,41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1
+  ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
+  ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
+  ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
+  ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
+  ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
+  ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
+  ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
+  ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
   };
-#define unbase64(x) unbase64_table[(int)(x)]
+#define unbase64(x) unbase64_table[(uint8_t)(x)]
 
 
 Handle<Value> Buffer::Base64Slice(const Arguments &args) {
index 512aea597007c709b541e9cbe295ba493124f1cd..26ebd4798a23f2b2ce56114718874ef56f7c5229 100644 (file)
@@ -256,6 +256,17 @@ b = new Buffer(expectedWhite, 'base64');
 assert.equal(quote.length, b.length);
 assert.equal(quote, b.toString('ascii', 0, quote.length));
 
+// check that the base64 decoder ignores illegal chars
+var expectedIllegal = expected.slice(0, 60) + " \x80" +
+                      expected.slice(60, 120) + " \xff" +
+                      expected.slice(120, 180) + " \x00" +
+                      expected.slice(180, 240) + " \x98" +
+                      expected.slice(240, 300) + "\x03" +
+                      expected.slice(300, 360) 
+b = new Buffer(expectedIllegal, 'base64');
+assert.equal(quote.length, b.length);
+assert.equal(quote, b.toString('ascii', 0, quote.length));
+
 
 assert.equal(new Buffer('', 'base64').toString(), '');
 assert.equal(new Buffer('K', 'base64').toString(), '');