[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: utf8 library may cause heap corruption
- From: Dirk Laurie <dirk.laurie@...>
- Date: Thu, 9 Feb 2017 14:30:39 +0200
2017-02-09 14:05 GMT+02:00 云风 Cloud Wu <cloudwu@gmail.com>:
> But there is another problem.
>
> local s = "\xE4\xBA"
> assert(utf8.len(s, 1, 2) == utf8.len(s .. "\x91",1,2)) -- failed
Why is this a problem? It should fail. s is not a valid UTF8 codepoint
("\xE4" promises three bytes, but there are only two). When you
supply the extra byte, there is one valid codepoint. starting between
charaters 1 and 2.
> utf8.len(s, 1, 2)
nil 1
> utf8.len(s .. "\x91",1,2)
1