libwally-core
libwally-core copied to clipboard
wally_psbt_from_bytes() is difficult to use
It does not tell the caller how many bytes it actually used, which is problematic if you're reading from a stream.
We work around this by calling wally_psbt_to_bytes() again!
Also, looking through the implementation, I am not convinced that you don't read past the end of the buffer in various cases. The usual way of handling this is to have all your internal demarshal functions take a "unsigned char **cursor, size_t *max", rather than having explicit length checks.
This has the strong advantage that you can simply continue demarshaling even if you run over the end, and just do the checks at the end.
See: https://github.com/ElementsProject/lightning/blob/master/wire/fromwire.c