Skip to content

Conversation

uniphil
Copy link
Owner

@uniphil uniphil commented May 2, 2025

removes all uses of unsafe. even the ones that are probably fine. also loses the specifically vectorized checks on insert in array form... could be brought back but i don't need that level of micro-optimization to bother getting it to work again.

the serde stuff has a redundant tuple wrapping everything that i need to remove. it's now using serde-derive, but i want to pass through from the public API to the representation directly. ORRRrrrr collapse the estimator to impl directly on the representation and then maybe no custom serde is needed at all.

i'll probably also add bincode derives (even more reason to collapse i guess)

going to roll ahead with this for UFOs since i can't wait for cloudflare/cardinality-estimator#12 any more. the serialized sketches likely won't be directly compatible, so this fork might just keep existing.

uniphil added 8 commits April 11, 2025 17:18
Cardinality estimator makes assumptions about the values it receives when deserializing which are upheld by _`serde_json`_ but not `serde` in general, leading to buffer overflows and other problems when used with other serde de/serializers.

I had the wildest crashes happening in a project, which I traced to being at least _related_ to cardinality-estimator, since they stopped when I shimmed it out. In narrowing down a smaller reproducible example, I found that using bincode with this library was sufficient to get buffer overflows: see https://github.com/uniphil/whose-overflow-is-it-anyway

This PR adds a fuzz target for `postcard`, whose API is close enough to `serde_json` for the change from the serde fuzz target to be a single line. It also adds postcard calls to the normal serde tests, though I wasn't able to specifically write a failing regression test case for it (I'm sure it's possible, just had to stop somewhere).

To be clear: this change only illustrates the issue and does not include a fix. Seems like fixing will require either

- fixing the deserialization logic to assume less about the inputs it receives (array alignment and length?), OR
- documenting explicitly that the `serde` support is **only** safe to work with `serde_json`.

Thanks @DavidBuchanan314 for help narrowing the source of the crashes <3
these ones are probably fine, probably just giving up perf here...
sure
i guess it's usize because a pointer is masked out from it... but imo it's really more about the bytes in more cases, and turning it into a pointer is a weird special case.
still need to fix up serialization but this is passing tests at least
@uniphil
Copy link
Owner Author

uniphil commented May 2, 2025

✅ custom serde: gone
❌ bincode derives: not for now (will just use serde feature of bincode. does bincode have a from and into derive thing like serde?)

uniphil added 5 commits May 6, 2025 15:04
serde_tuple didn't like the const generics (or just the generics?)

anyway for compact rep probably use bincode
@uniphil uniphil merged commit af838b1 into main May 6, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant