diff options
author | theduke <reg@theduke.at> | 2015-11-26 16:05:24 +0100 |
---|---|---|
committer | theduke <reg@theduke.at> | 2015-11-26 16:05:24 +0100 |
commit | 25b605a3a2310a6bc9822491e3925b606c9940b3 (patch) | |
tree | bee2274acec457dad29bf8a001dc5ee100126b54 /lib/pure | |
parent | eaed36092c5caa5854dcdb4bb205a3c1050e323c (diff) | |
download | Nim-25b605a3a2310a6bc9822491e3925b606c9940b3.tar.gz |
validateUtf8: catch overlong ascii
Make unicode.validateUtf8() check for overlong ascii representations, which are 2 bytes long and start with c0 or c1.
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/unicode.nim | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/lib/pure/unicode.nim b/lib/pure/unicode.nim index b059a7315..45f52eb7f 100644 --- a/lib/pure/unicode.nim +++ b/lib/pure/unicode.nim @@ -114,6 +114,7 @@ proc validateUtf8*(s: string): int = if ord(s[i]) <=% 127: inc(i) elif ord(s[i]) shr 5 == 0b110: + if ord(s[i]) < 0xc2: return i # Catch overlong ascii representations. if i+1 < L and ord(s[i+1]) shr 6 == 0b10: inc(i, 2) else: return i elif ord(s[i]) shr 4 == 0b1110: |