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

Platform interoperability weirdness #64

Closed
Zaerei opened this issue Mar 18, 2016 · 2 comments
Closed

Platform interoperability weirdness #64

Zaerei opened this issue Mar 18, 2016 · 2 comments

Comments

@Zaerei
Copy link

@Zaerei Zaerei commented Mar 18, 2016

I have to admit I'm not 100% sure whether this problem is on bincode or flate2 (Zlib Encoder/Decoder)'s side, but I'm having trouble decoding a file I made on Linux in Windows 10. The file opens fine on the Linux install (and it's the same physical box so no weird hardware issues). Same version of Rust on both (nightly March 9, 2016). The struct is:

pub enum RecordingState {
    Action(Action),
    Reset(AleSystemState),
    ChangeGame(Rom,f32,i32),
}
pub struct Rom {
    pub rom_path: PathBuf,
    pub data: Vec<u8>,
}

And AleSystemState is encoded/decoded as a Vec<i8>. The file in question is a series of individual encodes of RecordingStates (not a Vec, a series of individual ones). The first one is always a ChangeGame(Rom,f32,f32) instruction. Action is just pub struct Action(pub i32);.

I managed to track the error down to the line:

let (rom,repeat_prob,seed) = match rustc_serialize::decode_from(&mut self.decoder, 
                                        bincode::SizeLimit::Infinite)
                                        .expect("Could not decode ROM as initial replay step") {
            ChangeGame(rom,repeat_prob,seed) => (rom,repeat_prob,seed),
            _ => panic!("Initial value in recording isn't ChangeGame")
        };

When I hit that line I do NOT get a normal Rust panic, instead I get:

fatal runtime error: out of memory
Illegal instruction

self.decoder is a ZlibDecoder<BufReader<File>>. The compression I encode with is Best.

The file that's breaking is here:
https://www.dropbox.com/s/ry9zhzlanvxaqkr/data.games?dl=0

It looks like my project is on 0.4.0, but I observe the same behavior after bumping to 0.5.1 even after re-encoding/decoding.

I'm trying to reproduce this with a smaller example, especially in order to determine if this is due to flate2 or this library. I'm only guessing bincode because of the size limit. I haven't had any luck triggering it so far though.

@TyOverby
Copy link
Collaborator

@TyOverby TyOverby commented Mar 18, 2016

The reason that you are getting an out of memory error is because you are using SizeLimit::Infinite and the data trying to deserialize the Vec is malformed, causing it to pre-allocate a huge amount of memory crashing your program.

As to why the data is malformed, I have no idea. Could you try the following:

  1. Remove the zlib decoder from the mix and see if it still reproduces.
  2. Do an encoding (without zlib) on both machines and see if they produce different output.
  3. Check for any platform specific structures that would be getting encoded.
@TyOverby
Copy link
Collaborator

@TyOverby TyOverby commented Apr 12, 2016

Without further information, I'm going to close this.

@TyOverby TyOverby closed this Apr 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.