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

Unable to deserialize_str strings which are larger than 4096. #32

Open
kvinwang opened this issue Dec 6, 2021 · 2 comments · May be fixed by #43
Open

Unable to deserialize_str strings which are larger than 4096. #32

kvinwang opened this issue Dec 6, 2021 · 2 comments · May be fixed by #43

Comments

@kvinwang
Copy link

kvinwang commented Dec 6, 2021

We are trying to use ciborium to ser/de some complicated data. Part of the data invokes the Deserializer::deserialize_str and fails with an error: invalid type: string, expected str. This is because that ciborium limit the deserialze_str size to a hard coded 4096.

See:

let mut scratch = [0; 4096];

Header::Text(Some(len)) if len <= self.scratch.len() => {

Would it better to export a configurable limitation or alloc the internal buffer adaptively?

@glebpom
Copy link
Contributor

glebpom commented Dec 15, 2021

Same problem for me. It seems like deserialize_string doesn't have the same limitation. Based on this implementation, it looks like strings are stored in segments with a size up to 4096, so they cannot be presented as &str. However, I would suggest improving the error message.

@crapStone crapStone linked a pull request Mar 8, 2022 that will close this issue
acfoltzer added a commit to acfoltzer/ciborium that referenced this issue Aug 30, 2022
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.
acfoltzer added a commit to acfoltzer/ciborium that referenced this issue Aug 30, 2022
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.
acfoltzer added a commit to acfoltzer/ciborium that referenced this issue Aug 30, 2022
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.
acfoltzer added a commit to acfoltzer/ciborium that referenced this issue Oct 6, 2022
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.
acfoltzer added a commit to acfoltzer/ciborium that referenced this issue Oct 12, 2022
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.
@dpal dpal added this to Enarx Board Jan 26, 2023
@nakedible-p
Copy link

Fixed in 0.2.1 and should be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New
Development

Successfully merging a pull request may close this issue.

3 participants