mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-01 19:58:15 +00:00
[Lua] Avoid infinite loop when creating empty string (#6614)
* [Lua] Avoid infinite loop when creating empty string * [Lua] Check empty string output
This commit is contained in:
@@ -50,7 +50,10 @@ function mt:Slice(startPos, endPos)
|
||||
-- updated the startPos based on the size of the
|
||||
-- value
|
||||
while startPos < endPos do
|
||||
local v = d[startPos] or '/0'
|
||||
local v = d[startPos]
|
||||
if not v or v == "" then
|
||||
v = '/0'
|
||||
end
|
||||
table.insert(b, v)
|
||||
startPos = startPos + #v
|
||||
end
|
||||
|
||||
@@ -222,6 +222,18 @@ local function testCanonicalData()
|
||||
checkReadBuffer(wireData)
|
||||
end
|
||||
|
||||
local function testCreateEmptyString()
|
||||
local b = flatbuffers.Builder(0)
|
||||
local str = b:CreateString("")
|
||||
monster.Start(b)
|
||||
monster.AddName(b, str)
|
||||
b:Finish(monster.End(b))
|
||||
local s = b:Output()
|
||||
local data = flatbuffers.binaryArray.New(s)
|
||||
local mon = monster.GetRootAsMonster(data, 0)
|
||||
assert(mon:Name() == "")
|
||||
end
|
||||
|
||||
local function benchmarkMakeMonster(count, reuseBuilder)
|
||||
local fbb = reuseBuilder and flatbuffers.Builder(0)
|
||||
local length = #(generateMonster(false, fbb))
|
||||
@@ -285,6 +297,10 @@ local tests =
|
||||
f = testCanonicalData,
|
||||
d = "Tests Canonical flatbuffer file included in repo"
|
||||
},
|
||||
{
|
||||
f = testCreateEmptyString,
|
||||
d = "Avoid infinite loop when creating empty string"
|
||||
},
|
||||
{
|
||||
f = getRootAs_canAcceptString,
|
||||
d = "Tests that GetRootAs<type>() generated methods accept strings"
|
||||
|
||||
Reference in New Issue
Block a user