Re: Undefined behavior in utf8_decode()

Sergey Bronnikov <[email protected]>
Newsgroups gmane.comp.lang.lua.general
Message-ID <[email protected]>
> May be an argument about whether the utf8 lib should detect invalid  
strings,
> or if it's the users job to sanitise before use. 

I suppose the first one, the Lua 5.5 Reference Manual says:

> If it finds any invalid byte sequence, returns fail plus the position of 
the first invalid byte.

Sergey

On Monday, February 16, 2026 at 7:53:45 PM UTC+3 Scott Morgan wrote:

On 16/02/2026 15:05, Sergey Bronnikov wrote: 
> 
> make MYCFLAGS=-fsanitize=undefined MYLDFLAGS=-fsanitize=undefined 
> echo "dXRmOC5sZW4n2b0B/4+Pj4+Pj48AACc=" | base64 --decode | ./lua - 
> 

d9 bd 01 ff 8f 8f 8f 8f 8f 8f 8f 00 00 

That doesn't appear to be valid UTF8 (0xff shouldn't appear in UTF8 
bytes[1]) 

May be an argument about whether the utf8 lib should detect invalid 
strings, or if it's the users job to sanitise before use. 

Scott 

[1] https://www.rfc-editor.org/rfc/rfc3629#page-3 
> The octet values C0, C1, F5 to FF never appear 

-- 
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/lua-l/a015e6da-2127-45f1-aa0d-a6b855b560c0n%40googlegroups.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.