api7 / jsonschema

Pure Lua JSON schema validator for Lua/LuaJIT
https://www.apiseven.com/
Apache License 2.0
119 stars 28 forks source link

endless loop in utf8_len #61

Closed danncy closed 2 years ago

danncy commented 3 years ago

function validatorlib.utf8_len(s) local c, j=0, 1 while j <= #s do local cb = str_byte(s, j) if cb >= 0 and cb <= 127 then j = j + 1 elseif cb >= 192 and cb <= 223 then j = j + 2 elseif cb >= 224 and cb <= 239 then j = j + 3 elseif cb >= 240 and cb <= 247 then j = j + 4 end c = c + 1 end return c end

input "%ff", after urldecode ,str_byte(s,j), when cb > 247,#s = 1, j = 1 , will cause endless loop

Gerrard-YNWA commented 3 years ago

@danncy Thanks for the report, @membphis I think it's indeed a serious problem, I will send a fix later.