diff --git a/crates/wasi-common/src/snapshots/wasi_snapshot_preview1.rs b/crates/wasi-common/src/snapshots/wasi_snapshot_preview1.rs index 794be79c9fc6..2f74b98aa88e 100644 --- a/crates/wasi-common/src/snapshots/wasi_snapshot_preview1.rs +++ b/crates/wasi-common/src/snapshots/wasi_snapshot_preview1.rs @@ -304,7 +304,6 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx { let dirent_len: types::Size = dirent_raw.len().try_into()?; let name_raw = name.as_bytes(); let name_len = name_raw.len().try_into()?; - let offset = dirent_len.checked_add(name_len).ok_or(Error::Overflow)?; // Copy as many bytes of the dirent as we can, up to the end of the buffer. let dirent_copy_len = min(dirent_len, buf_len - bufused); @@ -318,6 +317,7 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx { } buf = buf.add(dirent_copy_len)?; + bufused = bufused.checked_add(dirent_copy_len).ok_or(Error::Overflow)?; // Copy as many bytes of the name as we can, up to the end of the buffer. let name_copy_len = min(name_len, buf_len - bufused); @@ -331,8 +331,7 @@ impl<'a> WasiSnapshotPreview1 for WasiCtx { } buf = buf.add(name_copy_len)?; - - bufused += offset; + bufused = bufused.checked_add(name_copy_len).ok_or(Error::Overflow)?; } Ok(bufused)