couchbase/fleece

Crash reusing Encoder after finish() w/o reset()

Closed this issue · 0 comments

snej commented

Encoder::finish() leaves the Encoder's internal stack empty. Unfortunately that's not the same state the encoder starts out in — it needs a fake placeholder collection on the stack — so encoding another object after `finish() leads to a crash when closing its outer dict/array. (It's an assertion failure in a debug build, a segfault in release.)

It's pretty rare to reuse an Encoder, but LiteCore does it for performance reasons: every database has a shared Encoder instance. There happens to be one case where the Encoder is reused without first calling reset on it, which triggered this.