-
Notifications
You must be signed in to change notification settings - Fork 65
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
fix: use allocating deserializers when scratch space exceeded #54
base: main
Are you sure you want to change the base?
Conversation
9dbfec2
to
b2f63b1
Compare
b2f63b1
to
d6b519b
Compare
@bstrie I rebased as you requested, but now there's a bunch of different clippy warnings, again not part of this change. |
@acfoltzer Thanks for the PR! (I just submitted a separate PR for the clippy stuff, let's not worry about that now.) Can you add test cases for both deserialize_str and deserialize_bytes here?
This is a good question. I assume that the current behavior is deliberately intended to accommodate the no_std use case. Indeed, the crates.io tags include the "No standard library" tag, so that looks to be an intended use case. It does seem peculiar that there are allocating deserializers that aren't guarded by any cfg; there already exists a |
Have you also seen #43 ? It appears to be trying to solve the same problem (although it never got beyond the draft stage), and does take into account the no_std use case. |
I did see that, but given the current de-facto lack of
Unfortunately the tests in |
@acfoltzer If no_std support is already broken then I'm fine accepting this PR without no_std guards, although I wouldn't want to actually perform a real release until no_std mode is fixed (although issuing a prerelease could be fine, if there's demand). As far as testing, I'm happy to accept one-off tests, as long as they guard against regressions in the behavior being added here. I wouldn't want to close #32 without a regression test of some kind. |
I've filed #59 to track the no_std issue. |
Issue enarx#32 describes a class of errors where `deserialize_str` (and `deserialize_bytes`) have match expressions that fall through to an error when the `Text` (`Bytes`) lengths are longer than can fit in the scratch array. This patch works around that limitation by delegating to the corresponding allocating methods `deserialize_string` (`deserialize_byte_buf`) in case the scratch space is too small. This should address the issue even for types whose `Deserialize` visitor does not implement `visit_string`, since the default implementation of that method delegates back to `visit_str` once the fully-deserialized `String` is in hand. This addition raises a question to me about the stance of the `ciborium` crate on `no_std`/`alloc` support. This workaround depends on being able to use `String` and `Vec`, which rules out `no_std`. But these allocating deserializers already exist in the code and don't appear to be guarded by `cfg` directives, so I don't believe this patch changes the level of support provided for these environments. Adds regression tests for slightly-too-long string and byte sequence roundtripping.
d6b519b
to
c32f3c9
Compare
@acfoltzer It appears that the tests fail in the case of |
Issue #32 describes a class of errors where
deserialize_str
(anddeserialize_bytes
) have match expressions that fall through to an error when theText
(Bytes
) lengths are longer than can fit in the scratch array.This patch works around that limitation by delegating to the corresponding allocating methods
deserialize_string
(deserialize_byte_buf
) in case the scratch space is too small.This should address the issue even for types whose
Deserialize
visitor does not implementvisit_string
, since the default implementation of that method delegates back tovisit_str
once the fully-deserializedString
is in hand.This addition raises a question to me about the stance of the
ciborium
crate onno_std
/alloc
support. This workaround depends on being able to useString
andVec
, which rules outno_std
. But these allocating deserializers already exist in the code and don't appear to be guarded bycfg
directives, so I don't believe this patch changes the level of support provided for these environments.