mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-01 18:43:57 +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
|
-- updated the startPos based on the size of the
|
||||||
-- value
|
-- value
|
||||||
while startPos < endPos do
|
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)
|
table.insert(b, v)
|
||||||
startPos = startPos + #v
|
startPos = startPos + #v
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -222,6 +222,18 @@ local function testCanonicalData()
|
|||||||
checkReadBuffer(wireData)
|
checkReadBuffer(wireData)
|
||||||
end
|
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 function benchmarkMakeMonster(count, reuseBuilder)
|
||||||
local fbb = reuseBuilder and flatbuffers.Builder(0)
|
local fbb = reuseBuilder and flatbuffers.Builder(0)
|
||||||
local length = #(generateMonster(false, fbb))
|
local length = #(generateMonster(false, fbb))
|
||||||
@@ -285,6 +297,10 @@ local tests =
|
|||||||
f = testCanonicalData,
|
f = testCanonicalData,
|
||||||
d = "Tests Canonical flatbuffer file included in repo"
|
d = "Tests Canonical flatbuffer file included in repo"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
f = testCreateEmptyString,
|
||||||
|
d = "Avoid infinite loop when creating empty string"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
f = getRootAs_canAcceptString,
|
f = getRootAs_canAcceptString,
|
||||||
d = "Tests that GetRootAs<type>() generated methods accept strings"
|
d = "Tests that GetRootAs<type>() generated methods accept strings"
|
||||||
|
|||||||
Reference in New Issue
Block a user