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

Segmentation fault / stack overflow #2645

Closed
m00nwtchr opened this issue Nov 5, 2023 · 2 comments
Closed

Segmentation fault / stack overflow #2645

m00nwtchr opened this issue Nov 5, 2023 · 2 comments

Comments

@m00nwtchr
Copy link

I'm getting a segfault and/or stack overflow whenever I try to deserialize my data using any serde compatible library (as far as i can tell, serialization works fine), I tried ron and serde_json.

Definitions: (Should the two main files involved)

Example json:

[
  {
    "info": {
      "name": "Lorem ipsum dolor sit amet",
      "shortName": "Lorem",
      "hash": "5035F594CD90296C",
      "publicationDate": "2222-09-22"
    },
    "merits": [
      {
        "name": "Lorem ipsum",
        "page": 91,
        "effects": [
          "Lorem ipsum dolor sit amet"
        ],
        "dotRating": 3,
        "prerequisites": [
          "Lorem ipsum",
          [
            "Lorem",
            3
          ]
        ]
      }
    ]
  }
]

(Not an actual sample, but I can't post that online and this still gives the error)

Example deserialization code:

use std::{fs::File, io::BufReader};

use cofd_schema::book::Book;

pub fn main() {
	let _: Vec<Book> = serde_json::from_reader(BufReader::new(
		File::open("books.json").unwrap(),
	))
	.unwrap();
}

Output:

$ cargo run --example=main
    Finished dev [unoptimized + debuginfo] target(s) in 0.09s
     Running `target/debug/examples/main`

thread 'main' has overflowed its stack
fatal runtime error: stack overflow
zsh: IOT instruction (core dumped)  cargo run --example=main
@m00nwtchr
Copy link
Author

m00nwtchr commented Nov 5, 2023

Oh, i found these repeating lines in the stacktrace:

#33 0x0000560e4cdef65b in serde::de::impls::{impl#197}::deserialize<cofd_schema::prerequisites::Prerequisite, serde::__private::de::content::ContentRefDeserializer<serde_json::error::Error>> (
    deserializer=...) at /home/m00n/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.190/src/de/impls.rs:762
#34 0x0000560e4cdc4a15 in cofd_schema::prerequisites::_::{impl#0}::deserialize::{closure#0}<serde::__private::de::content::ContentRefDeserializer<serde_json::error::Error>> ()
    at /home/m00n/.local/share/cargo/git/checkouts/cofd-miner-56c4e31c2b72a1f5/961d25b/cofd-schema/src/prerequisites.rs:17
#35 0x0000560e4cdc4417 in cofd_schema::prerequisites::_::{impl#0}::deserialize<serde::__private::de::content::ContentRefDeserializer<serde_json::error::Error>> (__deserializer=...)
    at /home/m00n/.local/share/cargo/git/checkouts/cofd-miner-56c4e31c2b72a1f5/961d25b/cofd-schem/src/prerequisites.rs:17

So i guess i managed to make an endless loop 😅

@m00nwtchr
Copy link
Author

m00nwtchr commented Nov 5, 2023

It looks like it was the: #[serde(untagged)] attribute in combination with a variant that (via a Box) contains its own enum.

Maybe this is something that serde could catch and raise a compile time error/warning about?

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

No branches or pull requests

1 participant