Skip to content

set_size can cause seg fault when value too large on macOS #700

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

Open
mikebenfield opened this issue Sep 2, 2017 · 9 comments
Open

set_size can cause seg fault when value too large on macOS #700

mikebenfield opened this issue Sep 2, 2017 · 9 comments

Comments

@mikebenfield
Copy link

mikebenfield commented Sep 2, 2017

Sometimes I get a panic; sometimes a seg fault.

$ cat src/main.rs

extern crate sdl2;

fn main() {
    let sdl = sdl2::init().unwrap();
    let vid = sdl.video().unwrap();
    let mut win = vid.window(&"", 128, 128)
        .build().unwrap();
    win.set_size(i32::max_value() as u32, 100);
}
$ cargo run
2017-09-01 17:57:12.947 sdl2_crash[11065:5671348] *** Assertion failure in -[_NSCGSWindow setFrame:], /Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1504.82.104/CGS.subproj/NSCGSWindow.m:663
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:335:20
note: Run with `RUST_BACKTRACE=1` for a backtrace.
fatal runtime error: failed to initiate panic, error 5
Abort trap: 6
$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target/debug/sdl2_crash`
2017-09-01 17:57:30.372 sdl2_crash[11080:5671827] *** Assertion failure in -[_NSCGSWindow setFrame:], /Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1504.82.104/CGS.subproj/NSCGSWindow.m:663
Segmentation fault: 11

Mac OS 10.12.4.

@Cobrand
Copy link
Member

Cobrand commented Sep 2, 2017

win.set_size(i32::max_value() as u32, 100);

How would you expect the library to behave?

@Cobrand
Copy link
Member

Cobrand commented Sep 2, 2017

Unable to reproduce; no crash on Linux.

@mikebenfield
Copy link
Author

mikebenfield commented Sep 3, 2017

How would you expect the library to behave?

Panic or return an error? Safe code in Rust isn't supposed to segfault.

@Cobrand
Copy link
Member

Cobrand commented Sep 3, 2017

The segfault is coming from your OS, not from SDL2. Can you sho me the full backtrace? I'd like to know where that panic comes from.

There is not much I can do aside from "assert"-ing that the new size is below a certain value that would be deemed safe, but again you shouldn't have to set your window to such a size in the first place; what would be a "too big" value for SDL2 to panic?

@mikebenfield
Copy link
Author

I've been unable to reproduce the panic; only a segfault, and I don't think I can get a backtrace from a segfault.

There is not much I can do aside from "assert"-ing that the new size is below a certain value that would be deemed safe

Yes, this is what I am asking for.

again you shouldn't have to set your window to such a size in the first place

Of course not; if my program did that, it would be a bug... which I would like to be easy to fix, because I got a panic or an error return, instead of a segfault.

@Cobrand
Copy link
Member

Cobrand commented Sep 3, 2017

Well, if you tell me what is the maximum value your OS accepts, we can make an assert of the like for sure.

@Cobrand Cobrand changed the title set_size can cause seg fault set_size can cause seg fault when value too large on macOS Sep 5, 2017
@ebarnard
Copy link
Contributor

From https://developer.apple.com/documentation/appkit/nswindow/1419753-setframe?language=objc

Max size (Window::set_size, Window::set_maximum_size, Window::set_minimum_size): 10000x10000
Max position (Window::set_position): (±16000, ±16000)

@mnmaita
Copy link
Contributor

mnmaita commented Sep 28, 2019

What would be the best way to check the current platform within the library?

@Cobrand
Copy link
Member

Cobrand commented Sep 29, 2019

Either at compile time with the "cfg" attributes, or at runtime using https://docs.rs/sdl2/0.32.2/sdl2/fn.get_platform.html

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

No branches or pull requests

4 participants