Skip to content

Commit 7c61f88

Browse files
anforowiczSkCQ
authored and
SkCQ
committed
[rust png] Delete incorrect memory safety comments.
In the past I have assumed that the mere **existence** of a `&mut` reference to uninitialized memory results in instant Undefined Behavior (UB), even if there are no explicit reads in the code. This scenario has been recently discussed in the internal chatroom about `unsafe` Rust code (see https://chat.google.com/room/AAAAhLsgrQ4/Fx2naiaXbeU) where rust-lang/unsafe-code-guidelines#346 was linked and where it seems that the consensus is to **not** treat `&mut uninit` as immediate UB. On one hand the discussions are still ongoing, but OTOH I don't want to make/spread safety notes that may very well be incorrect and overly conservative. So, for now, let me delete the related safety comments from `FFI.rs`. Bug: chromium:356884491 Change-Id: Ica15532493dc0c35b12332df04306fe87be10d3e Reviewed-on: https://skia-review.googlesource.com/c/skia/+/904956 Auto-Submit: Łukasz Anforowicz <[email protected]> Commit-Queue: Daniel Dilan <[email protected]> Reviewed-by: Daniel Dilan <[email protected]>
1 parent f7cb94e commit 7c61f88

File tree

1 file changed

+0
-16
lines changed
  • experimental/rust_png/ffi

1 file changed

+0
-16
lines changed

experimental/rust_png/ffi/FFI.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,6 @@ impl Reader {
261261
/// If the decoded PNG image contained a `cHRM` chunk then `try_get_chrm`
262262
/// returns `true` and populates the out parameters (`wx`, `wy`, `rx`,
263263
/// etc.). Otherwise, returns `false`.
264-
///
265-
/// C++/FFI safety: The caller has to guarantee that all the outputs /
266-
/// `&mut` values have been initialized (unlike in C++, where such
267-
/// guarantees are typically not needed for output parameters).
268264
fn try_get_chrm(
269265
&self,
270266
wx: &mut f32,
@@ -296,10 +292,6 @@ impl Reader {
296292
/// If the decoded PNG image contained a `gAMA` chunk then `try_get_gama`
297293
/// returns `true` and populates the `gamma` out parameter. Otherwise,
298294
/// returns `false`.
299-
///
300-
/// C++/FFI safety: The caller has to guarantee that all the outputs /
301-
/// `&mut` values have been initialized (unlike in C++, where such
302-
/// guarantees are typically not needed for output parameters).
303295
fn try_get_gama(&self, gamma: &mut f32) -> bool {
304296
match self.reader.info().gama_chunk.as_ref() {
305297
None => false,
@@ -360,10 +352,6 @@ impl Reader {
360352
/// Returns `png::FrameControl` information.
361353
///
362354
/// Panics if no `fcTL` chunk hasn't been parsed yet.
363-
///
364-
/// C++/FFI safety: The caller has to guarantee that all the outputs /
365-
/// `&mut` values have been initialized (unlike in C++, where such
366-
/// guarantees are typically not needed for output parameters).
367355
fn get_fctl_info(
368356
self: &Reader,
369357
width: &mut u32,
@@ -424,10 +412,6 @@ impl Reader {
424412

425413
/// Expands the last decoded interlaced row - see
426414
/// https://docs.rs/png/latest/png/fn.expand_interlaced_row
427-
///
428-
/// C++/FFI safety: The caller has to guarantee that `img` doesn't
429-
/// contain uninitialized memory (this is a bit different from C++,
430-
/// where a write-only access may not need such guarantees).
431415
fn expand_last_interlaced_row(
432416
&self,
433417
img: &mut [u8],

0 commit comments

Comments
 (0)