Verify the texture buffer for tex_image_2d() call.#122
Verify the texture buffer for tex_image_2d() call.#122JerryShih wants to merge 1 commit intoservo:mainfrom
Conversation
src/gl_fns.rs
Outdated
| match opt_data { | ||
| Some(data) => { | ||
| if let Some(data) = opt_data { | ||
| if !data.is_empty() { |
There was a problem hiding this comment.
What about:
let ptr = match opt_data {
Some(data) => {
if data.is_empty() { ptr::null() } else { data.as_ptr() }
}
None => ptr::null(),
};And just a single call after that?
There was a problem hiding this comment.
let ptr = match opt_data {
Some(data) if !data.is_empty() => data.as_ptr(),
_ => ptr::null(),
};| } | ||
| } | ||
|
|
||
| // FIXME: Does not verify buffer size -- unsafe! |
There was a problem hiding this comment.
Also, this is still true (we don't verify that there is enough data on the buffer for the given format, width and height), so please add these comments back.
We will have a crash when we pass an empty slice to tex_image_2d(). Turn to pass a null() to tex_image_2d() if we have an empty slice.
|
I don't understand. Why are we calling it with an empty slice? |
@kvark The tex_image_2d() already could accept null() and create a empty texture. I think the "empty slice" should have the same semantic. That's why I only convert the empty slice to null() here. |
kvark
left a comment
There was a problem hiding this comment.
@JerryShih just because the Gecko binding code is incorrect, doesn't mean that gleam should accommodate to it. Gecko should pass None instead of Option<&[]>.
|
@kvark
|
I consider that being answered as well. Basically, it's just not sound to mix up the semantics of
The API will also crash if the slice is non-zero but less then the requested data size. Your PR doesn't handle that range of cases, and I see an empty slice just being a sub-case of it.
We should verify that the slice contains at least the required number of elements in order to prevent the crash. Notice the comment:
It accepts |
|
I don't see how this can be done exhaustively, given this also involves various |
|
☔ The latest upstream changes (presumably #181) made this pull request unmergeable. Please resolve the merge conflicts. |
r? @glennw @kvark
We might hit the crash when we pass an empty slice to tex_image_2d().
This change is