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

Panic on input that is not valid UTF8 when deserializing to a RawValue #755

Closed
wlinna opened this issue Feb 26, 2021 · 1 comment
Closed

Panic on input that is not valid UTF8 when deserializing to a RawValue #755

wlinna opened this issue Feb 26, 2021 · 1 comment
Labels
bug

Comments

@wlinna
Copy link

@wlinna wlinna commented Feb 26, 2021

Very similar to this issue: #99

However, I ran into this problem when deserializing to a RawValue.

let json_str2 = &[ b'"', b'\xCE', b'\xF8', b'"'];
let v2: serde_json::Result<Box<serde_json::value::RawValue>> = serde_json::from_slice(json_str2);

I get this kind of backtrace:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Utf8Error { valid_up_to: 1, error_len: Some(1) }', C:\Users\X\.cargo\registry\src\github.com-1ecc6299db9ec823\serde_json-1.0.63\src\read.rs:590:39
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b\/library\std\src\panicking.rs:493
   1: core::panicking::panic_fmt
             at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b\/library\core\src\panicking.rs:92
   2: core::option::expect_none_failed
             at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b\/library\core\src\option.rs:1268
   3: core::result::Result<str, core::str::error::Utf8Error>::unwrap<str,core::str::error::Utf8Error>
             at C:\Users\X\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\result.rs:973
   4: serde_json::read::{{impl}}::end_raw_buffering<serde_json::raw::{{impl}}::deserialize::BoxedVisitor>
             at C:\Users\X\.cargo\registry\src\github.com-1ecc6299db9ec823\serde_json-1.0.63\src\read.rs:590
   5: serde_json::de::Deserializer<serde_json::read::SliceRead>::deserialize_raw_value<serde_json::read::SliceRead,serde_json::raw::{{impl}}::deserialize::BoxedVisitor>
             at C:\Users\X\.cargo\registry\src\github.com-1ecc6299db9ec823\serde_json-1.0.63\src\de.rs:1194
   6: serde_json::de::{{impl}}::deserialize_newtype_struct<serde_json::read::SliceRead,serde_json::raw::{{impl}}::deserialize::BoxedVisitor>
             at C:\Users\X\.cargo\registry\src\github.com-1ecc6299db9ec823\serde_json-1.0.63\src\de.rs:1695
   7: serde_json::raw::{{impl}}::deserialize<mut serde_json::de::Deserializer<serde_json::read::SliceRead>*>
             at C:\Users\X\.cargo\registry\src\github.com-1ecc6299db9ec823\serde_json-1.0.63\src\raw.rs:347
   8: serde_json::de::from_trait<serde_json::read::SliceRead,alloc::boxed::Box<serde_json::raw::RawValue, alloc::alloc::Global>>
             at C:\Users\X\.cargo\registry\src\github.com-1ecc6299db9ec823\serde_json-1.0.63\src\de.rs:2386
   9: serde_json::de::from_slice<alloc::boxed::Box<serde_json::raw::RawValue, alloc::alloc::Global>>
             at C:\Users\X\.cargo\registry\src\github.com-1ecc6299db9ec823\serde_json-1.0.63\src\de.rs:2544
  10: gltf_data_packer::main
             at .\src\main.rs:34
  11: core::ops::function::FnOnce::call_once<fn(),tuple<>>
             at C:\Users\X\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:227

I encountered this issue when parsing a glTF-file: gltf-rs/gltf#298

@wlinna wlinna changed the title Panic on input that is not valid UTF8 when deserializing to RawValue Panic on input that is not valid UTF8 when deserializing to a RawValue Feb 26, 2021
@dtolnay dtolnay added the bug label Feb 28, 2021
@dtolnay dtolnay closed this in #757 Feb 28, 2021
@dtolnay
Copy link
Member

@dtolnay dtolnay commented Feb 28, 2021

Thanks, fixed in 1.0.64.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants