Closed anuraaga closed 12 months ago
Sorry it seems the issue may actually be Wasm specific so might not be needed here. Will double-check.
Hmm, interesting - I don't think its great to add a custom patch for musl, mainly since we're trying to keep the diff between upstream Postgres and libpg_query as small as we can.
It appears that Postgres 16 introduced the use of pg_strtoint32_safe
in this code path (as part of faff8f8e47f), which I believe should be safe from overruns (per the name):
https://github.com/postgres/postgres/blob/master/src/backend/parser/scan.l#L1372
Maybe we should revisit whether this is a problem on the 16 branch? (see #220, expecting to have this available soon)
Thanks for the pointer, indeed it seems worth seeing how it works with postgres 16. Will close this for now since looks like it should be fine then.
I have compiled this library to Wasm using wasi-sdk, which uses musl for libc. I noticed that musl seems to have an overflow related bug.
https://www.openwall.com/lists/musl/2023/12/01/1
Notably, the tests with large numbers was failing, recognizing them as
ICONST
https://github.com/pganalyze/libpg_query/blob/15-latest/test/scan_tests.c#L34
I came up with a patch to workaround it by knowing what the longest integer string would be
https://github.com/wasilibs/go-pgquery/blob/main/buildtools/wasm/patch-musl.txt#L9
AFAIK, this issue is not Wasm-specific and would happen for any musl user. Would it be worth adding this patch to this project? I can send a PR if it makes sense.