1 Decoding base64 data with the `Z` format of the struct module hung when 2 whitespace followed a padding character. The loops skipping whitespace 3 after the first and after the last `=` never advanced the read position, 4 so they spun forever on the first whitespace character, which made a 5 trailing newline in otherwise valid base64 input hang the program. 6 7 1. Whitespace after the final padding character. 8 9 -- Testcase -- 10 let struct; 11 12 try { 13 struct = require('struct'); 14 } 15 catch (e) { 16 exit(77); 17 } 18 19 for (let input in [ 'Zm8= ', 'Zm8=\n', 'Zg==\t', 'Zm9vYg==\r\n' ]) 20 print(hexenc(struct.pack('Z', input)), "\n"); 21 -- End -- 22 23 -- Args -- 24 -R 25 -- End -- 26 27 -- Expect stdout -- 28 666f 29 666f 30 66 31 666f6f62 32 -- End -- 33 34 35 2. Whitespace between two padding characters. 36 37 -- Testcase -- 38 let struct; 39 40 try { 41 struct = require('struct'); 42 } 43 catch (e) { 44 exit(77); 45 } 46 47 for (let input in [ 'Zg= =', 'Zg=\n=', 'Zg=\t \r\n=\n' ]) 48 print(hexenc(struct.pack('Z', input)), "\n"); 49 -- End -- 50 51 -- Args -- 52 -R 53 -- End -- 54 55 -- Expect stdout -- 56 66 57 66 58 66 59 -- End --
This page was automatically generated by LXR 0.3.1. • OpenWrt