Closed ioguix closed 1 year ago
This is same as https://github.com/supabase/vault/issues/3, interesting thing is it is only on macOS, not on Linux.
Well, the case I describe here is under linux.
I think it comes from the size allocated in pgsodium_crypto_aead_det_decrypt_by_id
. It should include the header size of varlena fields:
- result = _pgsodium_zalloc_bytea (result_len);
+ result = _pgsodium_zalloc_bytea (result_len + VARHDRSZ);
Note that this varlena header size is include at the end of function when setting the variable size:
SET_VARSIZE (result, VARHDRSZ + result_len);
A test with this patch removes the warning on my side.
A quick glance at other functions around shows htere's some more places that need to be fixed as well.
Well snap, I thought I caught these cases but must have missed a couple, I'm adding a debug build to my test runner so that it compiles with --enabled-cassert
and I'll push a fix today. Thank you @ioguix !
Yep clearly some confusion going on all this time on my part on the varlen headers. Using the stock upstream dockerfile as an expedient was clearly the too lazy approach, so I've added a debug dockerfile that enables cassert and gdb and turns off optimizations etc, and some others, I've got a branch up here
and I'm working my way through these in the tests one by one. Feel free to comment on this approach if you have any suggestions.
Fixed with #46
Hi,
I have a memory warning when using PostgreSQL 15.1 compiled with
--enabled-cassert
(enablesMEMORY_CONTEXT_CHECKING
) and current HEAD of pgsodium. See:I might be wrong, but I suspect some missing header size or something related when allocating space in
pgsodium_crypto_aead_det_encrypt_by_id
and other equivalent funcs. Which means more data are written to in the allocated space than asked when the data AND its header are written there.By the way, note that if I give
NULL
as additional data, it just crash:The backtrace:
The source code being:
Regards,