Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

循环引用场景下会导致stack overflow #250

Open
Water-Melon opened this issue Sep 11, 2023 · 1 comment
Open

循环引用场景下会导致stack overflow #250

Water-Melon opened this issue Sep 11, 2023 · 1 comment
Labels

Comments

@Water-Melon
Copy link

local pb = require "pb"
local protoc = require "protoc"

assert(protoc:load [[
   message Phone {
      optional string name        = 1;
      optional int64  phonenumber = 2;
      optional Person item        = 3;
   }
   message Person {
      optional string name     = 1;
      optional int32  age      = 2;
      optional string address  = 3;
      repeated Phone  contacts = 4;
   } ]])

local data = {
   name = "ilse",
   age  = 18,
   contacts = {
      { name = "alice", phonenumber = 12312341234 }
   }
}
data.contacts[1].item = data

local bytes = pb.encode("Person", data)

执行这段代码会得到如下结果

lua: a.lua:26: stack overflow (message too many levels)
stack traceback:
	[C]: in function 'encode'
	a.lua:26: in main chunk
	[C]: ?

虽然可以利用pcall来解决,但是是否应该在encode中对这种数据循环引用的情况做一些检查来避免栈满的情况呢?

@starwing
Copy link
Owner

这种肯定是直接报error的,没别的处理方法。lua-pb的设计是尽量不做检查,以提高性能。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants