Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add borsh serialization support #313

Merged
merged 7 commits into from
Feb 29, 2024

Conversation

sug0
Copy link
Contributor

@sug0 sug0 commented Feb 20, 2024

Add support to serialize maps and sets with borsh.

@sug0 sug0 marked this pull request as draft February 20, 2024 14:52
@sug0 sug0 marked this pull request as ready for review February 20, 2024 14:57
Cargo.toml Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
src/borsh.rs Outdated Show resolved Hide resolved
src/borsh.rs Outdated Show resolved Hide resolved
@sug0 sug0 marked this pull request as draft February 21, 2024 10:43
@sug0 sug0 requested a review from cuviper February 21, 2024 23:05
@sug0 sug0 marked this pull request as ready for review February 21, 2024 23:05
@sug0 sug0 force-pushed the heliax/borsh-support branch 2 times, most recently from 149d560 to 88a5692 Compare February 21, 2024 23:22
Cargo.toml Outdated Show resolved Hide resolved
src/borsh.rs Show resolved Hide resolved
src/borsh.rs Show resolved Hide resolved
@sug0 sug0 requested a review from cuviper February 26, 2024 10:18
@sug0 sug0 marked this pull request as draft February 26, 2024 12:33
@sug0
Copy link
Contributor Author

sug0 commented Feb 26, 2024

@cuviper the new deserialization code in spite of working correctly, introduced some exploits related with OOM errors. I'm inclined to rollback to Vec's borsh deserialization code, considering the gains in performance of the new approach are very minute anyway, and their deserialization code already solves the problem at hand. lmk what you think

@cuviper
Copy link
Member

cuviper commented Feb 26, 2024

introduced some exploits related with OOM errors.

Please explain this! If there's an "exploit" footgun here, it needs to be commented at the very least.

@sug0
Copy link
Contributor Author

sug0 commented Feb 26, 2024

@cuviper hm the problem is this deserialization code I wrote is blindly allocating a buffer for incoming items from a stream. the deserialization code in borsh for collections already guards against OOM related issues by limiting the size of allocations (possibly why it's occasionally slower in the benches I ran).

I'll revert the deserialization code to use Vec::deserialize_from_reader as I had before

@cuviper
Copy link
Member

cuviper commented Feb 26, 2024

Oh, I see -- I should really add limits to serde size_hint() deserializers as well, as they do in their own impls.

@sug0 sug0 marked this pull request as ready for review February 27, 2024 09:57
Copy link
Member

@cuviper cuviper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI failed on MSRV --all-features, since borsh wants 1.66, so I guess we need to reduce that job to the list of features that do work with 1.63. (I don't want to raise MSRV just for an optional feature.)

src/borsh.rs Outdated Show resolved Hide resolved
src/borsh.rs Outdated Show resolved Hide resolved
src/borsh.rs Outdated Show resolved Hide resolved
@cuviper
Copy link
Member

cuviper commented Feb 28, 2024

Your branch is not open to maintainer pushes, so I put suggested changes in my fork:
heliaxdev/indexmap@heliax/borsh-support...cuviper:indexmap:borsh-support

@sug0
Copy link
Contributor Author

sug0 commented Feb 29, 2024

@cuviper thanks for the patches! I've included them in this branch

@sug0 sug0 requested a review from cuviper February 29, 2024 12:54
@sug0
Copy link
Contributor Author

sug0 commented Feb 29, 2024

rebased on 2.2.4

@cuviper cuviper added this pull request to the merge queue Feb 29, 2024
Merged via the queue into indexmap-rs:master with commit c934ace Feb 29, 2024
16 checks passed
@sug0 sug0 deleted the heliax/borsh-support branch February 29, 2024 19:26
@cuviper
Copy link
Member

cuviper commented Feb 29, 2024

This has been published in 2.2.5!

@sug0
Copy link
Contributor Author

sug0 commented Feb 29, 2024

sweet. thanks!

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.

2 participants