Repository navigation
Cap every image read and fix the 1×1 Hi-Z mip (#400) - #401
Conversation
|
@coderabbitai review |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
b6969ed to
05c83d0
Compare
There was a problem hiding this comment.
Stale comment
Changes requested. The new sync cap and the 1×1 Hi-Z mip are sound. #400's exit criterion is still open: uncapped image reads remain in both crates, including the editor's glTF import.
What holds
read_limited_image_bytesrejects a regular file frommetadata().len()when that length is overMAX_IMAGE_ALLOC(64 MiB) and thentakes only that length. A non-file stops at the cap with no extra probe byte. A stat/open swap stays inside the cap, because thetakelimit is the length that was already compared. An exact-cap fifo is rejected;fifo_at_the_cap_does_not_read_one_more_bytestill locks that.read_capped_imagenow runs the same helper onspawn_blocking, so a stalled fifo occupies a blocking thread.TextureStreamingManagerstill drops viashutdown_timeoutof 500 ms. The comment ontexture_streaming.rs:16still namesstd::fs::read.
HizPyramid::newat 1×1 used to requestmip_level_count0 (log2(1)is 0)..max(1.0)yields 1, which is the wgpu maximum for a 1×1 texture.ceil(log2(n))never exceedsfloor(log2(n)) + 1, so larger frames stay legal. The copy shader returns whencoordsis outsidetextureDimensions, so the 8×8 workgroup on a 1×1 image is in bounds. The downsample loop is empty (saturating_sub(1)). Existing tests still lock 1920→11 and 1024→10. The new test builds the 1×1 pyramid; it records the copy and does not submit. Creation is the failure mode wgpu rejects.No new dependency, no
Cargo.tomlchange, no newunsafe. Cargo deny and cargo-audit succeeded (run 39561221108). Determinism is intact: Hi-Z is presentation-only (trace invariant 21;sample_hizdefaults off; nothing reads the pyramid back into the sim), and image I/O is off the tick.determinism-replaycompare succeeded on Ubuntu, Windows, and macOS (run 39561221026). The v1.49 stamp correctly names parent8b4caa27and says that commit does not contain this helper. The phase-plan Occlusion / Hi-Z row matches the gated pyramid.
NaniteCullingPipeline(nanite_gpu_culling.rs:197) still passes(edge as f32).log2().ceil() as u32straight tomip_level_count. A 1×1 Nanite target is still 0.draw_intodoes not record that pyramid. Latent, same formula.What blocks
data:glTF images are still uncapped in the match arm added to cap file URIs (lib.rs).load_uri_bytesbase64-decodes the whole payload, thendecode_image_bytesapplies the limits. External buffer URIs still use uncappedstd::fs::read(lib.rs:811) before a buffer-view image is sliced.- The editor does not use this helper.
mesh_gltf::load_gltf(mesh_gltf.rs:50), called fromengine_adapter.rsload_gltf_model, loads images withgltf::import(gltf 1.4.1).Scheme::read/read_to_endallocatesmetadata.len() + 1and reads the whole file.load_from_memory_with_formatuses image 0.25.8Limits::default: no edge cap,max_alloc512 MiB (eight timesMAX_IMAGE_ALLOC).load_rgba8isimage::open(mesh_gltf.rs:521) for Poly Haven sidecars.jail_gltf_urireturnsOk(())fordata:and checks the raw string. gltf then percent-decodes (urlencoding::decode) and honorsfile://. A URI whose raw components are the literal%2e%2epassessafe_under, and import resolves...file:///etc/passwdis a relative path to the jail and an absolute read inScheme::File.cell_loader::load_asset(AssetKind::Texture) is an uncappedtokio::fs::read. Scene streaming calls it for every asset on a cell (astraweave-scene/src/streaming.rs:193) and discards theResult.- KTX2 dimensions. The file cap does not bound
pixel_width/pixel_height(u32). The BC path allocates(width * height)asu32math, which wraps in release, with noMAX_IMAGE_EDGEcheck. The new smoke test asserts the fallbackexpect, so an uncappedload_ktx2_to_rgbathat fails the header parse still goes green.The asset-crate file branch does not percent-decode and does not special-case
file://, so it does not have the editor bypass. It jails to process cwd, not the glTF directory, and it duplicatesload_uri_bytesinstead of sharing one read. The v1.49 notice names the smoke-test fallback and omitsload_ktx2_to_rgba.Sent by Cursor Automation: ASTRA PR AUDIT AGENT
|
The remaining uncapped image reads stay out of this PR. They are #408 (deferred-failure, owner @lazyxeon): The render-trace notice on this head is v1.51 and names parent |
There was a problem hiding this comment.
Stale comment
Adversarial review of
05c83d09against49d289eb. The shared file cap is the right shape. Two image allocations this diff touches are still unbounded, and the issue #400 exit line (no uncapped image read left inastraweave-renderorastraweave-asset) is not met. CI on this head was still pending, so replay, cargo-audit, and cargo-deny were not observed here. NoCargo.tomlchange and no newunsafe.What holds
read_limited_image_bytesrejects a regular file frommetadata().len()beforeread, thentake(meta.len())so a file that grows after the stat stays inside that length. A fifo or other non-file usestake(MAX_IMAGE_ALLOC)and fails closed when the read returns exactly the cap, so it does not block on one more byte.std::io::Takeenforces that limit inread/read_buf(Rust 1.89). Symlinks are followed bymetadata, so a link to a file over the cap is rejected./dev/zerois not a regular file, so the read stops at 64 MiB and errors.open_limited_image,Texture::from_file_with_usage,read_capped_image(spawn_blocking; the?unwraps only theJoinError), the ktx2 byte read, and a non-data:glTF image URI call that helper. No new crate.The 1×1 Hi-Z change matches the existing contract.
ceil(log2(1))is 0 and wgpu rejectsmip_level_count0..max(1.0)makes that one mip. Edges ≥ 2 stay onceil(log2)(the 1024 → 10 and 1920 → 11 tests).buildusessaturating_sub(1), so a one-mip pyramid only copies.copy_depthreturns whencoordsis outsidetextureDimensions.record_hizalready clamps the extent with.max(1)and runs only whensample_hizis set (default false). Nothing indraw_intosamplesHizPyramid::view.Determinism
No sim write, no
SimRng, no wall clock on the read path.log2(1.0)is exact on IEEE-754, so the 1×1 mip count does not fork across Windows, Linux, and macOS. Replay inputs are untouched. Texture I/O and the pyramid stay presentation-side.spawn_blockingchanges which pool performs the read; it does not enter the ECS tick.Does not hold
load_ktx2_to_rgbacaps the file and then allocates frompixel_width×pixel_heightwith no edge or alloc check. A file under 64 MiB can still request a multi-gigabyte pixel buffer. The new smoke test is a sparsecap + 1file, so it never reaches that header.- The glTF
data:arm still base64-decodes the entire payload beforedecode_limited_image. The file arm copies thecurrent_dir()jail instead of the glTF directory used by the dependency scan.mesh_gltf::load_rgba8(image::open, featuregltf-assets) andcell_loader::load_assetforAssetKind::Texture(fs::read) are still uncapped.load_uri_bytesstillstd::fs::reads buffer files with no cap.from_file_with_usage_rejects_a_file_over_the_capreturns success when no wgpu adapter exists, so that sync path is unlocked on a CPU-only run. The 1×1 Hi-Z assert sits behind the same kind of skip, andNaniteCullingPipeline(nanite_gpu_culling.rs:197) still requestsmip_level_count0 at 1×1.draw_intodoes not record that pyramid.- The trace row still says “stamp updated on merge”. The commit message says that phrase is retired and that the stamp names
8b4caa27. The file correctly names parent49d289eb.Sent by Cursor Automation: ASTRA PR AUDIT AGENT
05c83d0 to
3383bad
Compare
There was a problem hiding this comment.
Stale comment
Adversarial re-review of
3383baddagainst040f24ae. The shared 64 MiB reader and the 1×1 Hi-Z mip are correct. This PR still does not meet #400's exit line (no uncapped image read left inastraweave-renderorastraweave-asset). #408 records four of those holes and leaves two that this diff touches.What holds
read_limited_image_bytesrejects a regular file frommetadata().len()before any byte is read, thentakes only that length, so a file that grows after the stat stays inside the length already compared. A fifo or other non-file usestake(MAX_IMAGE_ALLOC)and fails closed when the read returns exactly the cap, so it does not block on one more byte.std::io::Takeenforces that limit. Symlinks are followed bymetadata, so a link to a file over the cap is rejected./dev/zerois not a regular file, so the read stops at 64 MiB and errors.open_limited_image,Texture::from_file_with_usage,read_capped_image,load_ktx2_to_rgba's file read, the ktx2 smoke fallback, and a non-data:glTF image URI call that helper.fifo_at_the_cap_does_not_read_one_more_bytestill drives the helper throughspawn_blocking. No new crate, noCargo.tomlchange, no newunsafe.
HizPyramid::new(1, 1)used to requestmip_level_count0 becauselog2(1)is 0 and wgpu rejects that..max(1.0)makes one mip. Edges ≥ 2 stay on the existingceil(log2)contract (1024 → 10, 1920 → 11). That count never exceedsfloor(log2(n)) + 1, so larger frames stay legal.buildusessaturating_sub(1), so a one-mip pyramid only copies.copy_depthreturns whencoordsis outsidetextureDimensions, so the 8×8 workgroup on a 1×1 image is in bounds.record_hizalready clamps the extent with.max(1)and runs only whensample_hizis set (default false). Nothing indraw_intosamplesHizPyramid::view.Security
The new file-URI arm jails with
safe_underagainst the process cwd. On this platformfile:///etc/passwdis a relative path (file:/etc/passwd), and a raw%2e%2ecomponent is not.., so this arm does not have the editorgltf::importbypass...and absolute paths stay rejected.safe_undercanonicalizes, then this arm opens that path again, so a symlink swapped in between is followed. The read is still size-capped; the jail is not.Determinism
No sim write, no
SimRng, no wall clock on the read path.log2(1.0)is exact, so the 1×1 mip count does not fork across Windows, Linux, and macOS. Texture I/O and the pyramid stay presentation-side.spawn_blockingchanges which pool performs the read; it does not enter the ECS tick. Replay compare passed on Ubuntu and Windows (run 39625465678). The macOS replay job was still pending at review time. Cargo deny and cargo-audit passed (run 39625465782). Gate (fmt, clippy, check) passed.Still open
data:glTF images still base64-decode the whole payload beforedecode_limited_image. External buffer URIs still use uncappedstd::fs::read(load_uri_bytes, line 811) before a buffer-view image is sliced. #408 names thedata:case and does not name the buffer read.load_ktx2_to_rgbacaps the file, then allocates frompixel_width×pixel_heightwith no edge check. Theu32product wraps in release. A header under 64 MiB can still request 16384² (about 1 GiB ofu32pixels and 1 GiB of RGBA) beforetexture2ddecoderchecks the level length. #408 item 4 matches this. The new smoke test never reaches the header.mesh_gltf::load_rgba8(image::open) andcell_loaderAssetKind::Texture(tokio::fs::read) are still uncapped. #408 owns both. The editor import path is the oneengine_adaptercalls.from_file_with_usage_rejects_a_file_over_the_capreturns success when no wgpu adapter exists. The read fails before the device is used. #408 does not cover this.asset.mdsays every glTF image URI uses the capped read. Adata:URI does not. Stage B2 still says image file URIs live inload_uri_bytes. The v1.53 notice is the accurate one.- The timestamp row still says “stamp updated on merge” for
36757dad. The current stamp correctly names parent040f24ae.NaniteCullingPipeline(nanite_gpu_culling.rs:197) still requestsmip_level_count0 at 1×1.draw_intodoes not record that pyramid.Do not close #400 on this PR. The helper and the forward 1×1 mip can land; the exit line cannot.
Sent by Cursor Automation: ASTRA PR AUDIT AGENT
read_limited_image_bytes is the sync cap. open_limited_image, from_file_with_usage, the ktx2 smoke fallback, and async read_capped_image call it. A 1x1 Hi-Z pyramid is one mip. The trace stamp names parent 8b4caa2. That merge holds the v1.48 io-util edit. The "stamp updated on merge" wording is retired. Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
3383bad to
56c061f
Compare
There was a problem hiding this comment.
Re-reviewed 56c061f2 against parent 417f267f. The sync cap and the 1×1 forward pyramid are sound. This still does not meet #400's exit line, and it should not close that issue.
What holds:
read_limited_image_bytesrejects a regular file frommetadatabefore any byte is read, thentakes only that length. A fifo or other non-regular file stops at 64 MiB and is rejected when the read is exactly the cap, so a writer that stalls after a full buffer is not probed one byte further. A stat/open swap still cannot return more than the cap: the regular arm is limited by the statted length, and the other arm bytake(cap).- Callers of that helper:
open_limited_image,Texture::from_file_with_usage,load_ktx2_to_rgba's file read, the ktx2 smoke fallback, a non-data:glTF image URI, and asyncread_capped_image(viaspawn_blocking, so the tokio worker is not blocked onstd::fs). No new dependency and no newunsafe. HizPyramid::newforces one mip at a 1×1 edge.buildusessaturating_sub(1), so that pyramid does not downsample.copy_depthreturns when the invocation is outsidetextureDimensions.record_hizalready clamps the frame with.max(1)and runs only whensample_hizis set. The default is false. Nothing indraw_intoreads the pyramid back, and this diff does not write simulation state, sample a wall clock, or draw an unseeded RNG. Replay identity is unchanged.f32::log2of these edges stays on the presentation path...and a leading/are rejected bysafe_under.file:/etc/passwdandfile:///etc/passwdare relative components (file:,etc,passwd), not absolute. The glTF crate hands the URI through as raw JSON, so%2Fis not a separator.
Still open on this head:
- A
data:image URI base64-decodes the whole payload before the 4096 / 64 MiB decoder limits. External.gltfbuffer URIs still use uncappedstd::fs::readinload_uri_bytes, andSource::Viewimages are slices of those buffers. #408 names thedata:image URI and does not name that buffer read. - The KTX2 file stops at 64 MiB. The header does not. A short file can still allocate the pixel buffers from
pixel_width * pixel_heightbeforetexture2ddecoderchecks the level length. #408 item 4. mesh_gltf::load_gltf/load_rgba8andcell_loaderAssetKind::Texturestay uncapped. #408.- The new cap tests for
from_file_with_usageandload_texture_asyncreturn success when the adapter probe fails, so a CPU-only run never calls the function under test. asset.mdstill says a glTF image URI uses the capped read. That is the non-data:arm only. Stage B2 still says image file URIs live inload_uri_bytes.- The rewritten timestamp row still says
36757dadwas "stamp updated on merge". The current stamp itself is right:417f267fis the parent, and the v1.53 notice names the new callers.
Trace Sync and Doc-Truth Lint are green on this head. Determinism, Security Audit, Render device validation, and the Gate job were still running at review time. I did not treat those as passed.
NaniteCullingPipeline (nanite_gpu_culling.rs:197) still passes unclamped ceil(log2) as mip_level_count. draw_into does not record that pyramid.
Sent by Cursor Automation: ASTRA PR AUDIT AGENT


Description
read_limited_image_bytesinastraweave_asset::image_limitsis the sync 64 MiB read. A regular file over the cap is rejected from its length before any byte is read. A fifo stops at the cap and is not probed one byte further.open_limited_image,Texture::from_file_with_usage, the ktx2 smoke-test fallback,load_ktx2_to_rgba, a non-data:glTF image file URI, and asyncread_capped_imagecall that helper. Tests cover a file over 64 MiB onopen_limited_image,from_file_with_usage, and the ktx2 smoke fallback.A 1×1
HizPyramidhas one mip.log2(1)is 0, and wgpu rejectsmip_level_count0.hiz_pyramid_creationbuilds that frame.Rebased onto main
040f24ae(#395). The render-trace notice is v1.53 and names that parent. That parent does not contain this read helper or the 1×1 mip fix. Main's atmosphere notices stay. The remaining uncapped readers are #408, not this PR.Type of change
Security Considerations
Checklist