lib/core: add failsafe to UTF8Codec::decode_string
authorLucas Bajolet <lucas.bajolet@gmail.com>
Fri, 11 May 2018 00:50:14 +0000 (20:50 -0400)
committerLucas Bajolet <lucas.bajolet@gmail.com>
Fri, 11 May 2018 03:16:40 +0000 (23:16 -0400)
Calling decode_string on the UTF-8 codec with a negative legth would
cause memmove to crash the program with a segfault.

Adding an assert gives more information on what went wrong and will help
investigate future bugs.

Signed-off-by: Lucas Bajolet <lucas.bajolet@gmail.com>

lib/core/codecs/utf8.nit

index 43f6235..d4d4a38 100644 (file)
@@ -68,6 +68,7 @@ private class UTF8Codec
        end
 
        redef fun decode_string(ns, len) do
+               assert len >= 0
                var ret = ns.to_s_unsafe(len, copy=false)
                var rit = ret.as(FlatString).items
                if rit == ns then