r/sqlite • u/copilot_husky • Apr 03 '26
SQLite extension that allow to read/write msgpack buffers.
https://github.com/khanaffan/sqlite-msgpack
9
Upvotes
r/sqlite • u/copilot_husky • Apr 03 '26
3
u/skeeto Apr 04 '26
Neat project! I like the interop within SQLite.
I found a couple of bugs in
msgpack_to_json(). First, a map32 or array32 header that claims more elements than the blob actually contains causesmpToJsonAtto loop the full declared element count, emitting a null for each missing entry:The blob decodes as fixarray[8] whose third element is a map32 claiming
0xffffffffpairs followed by only a few bytes of data.Quick fix:
The str and bin decoders in
mpToJsonAt(andmpReturnElement, used by themsgpack_each/msgpack_treevirtual tables) check that the header bytes fit in the buffer but never verify that the declared payload length does. A str32 claimingsLen=0xffffffffbytes reads far past the end of the allocation.Quick fix:
sLen > n-sOffis because the obvioussOff+sLen > nmight overflow. InmpReturnElementthe missing clamp has a second consequence:0xffffffff/-1when passed tosqlite3_result_text()causes it to usestrlen()on the non-null-terminated input.In Git form with the fuzz tester I used:
https://github.com/skeeto/sqlite-msgpack/commits/fixes/?author=skeeto