Skip to content

fix: replace bare assert with runtime checks in engine, index, and export#535

Open
tombudd wants to merge 1 commit intogoogle-deepmind:mainfrom
tombudd:una/fix-assert-to-runtime-checks
Open

fix: replace bare assert with runtime checks in engine, index, and export#535
tombudd wants to merge 1 commit intogoogle-deepmind:mainfrom
tombudd:una/fix-assert-to-runtime-checks

Conversation

@tombudd
Copy link

@tombudd tombudd commented Mar 23, 2026

Summary

Replace 6 bare assert statements with proper raise ValueError/RuntimeError that persist in optimized Python builds. Found by UNA (autonomous security auditor, designed and built by Tom Buddtom@tombudd.com).

1. Bounds validation in Camera.select() — engine.py

File: dm_control/mujoco/engine.py:975-987

Four assert statements validate that body_id, geom_id, flex_id, and skin_id are within the physics model's bounds. When Python runs with -O, these checks are stripped — allowing invalid IDs to silently pass through to MuJoCo, potentially causing out-of-bounds memory access in the underlying C library.

Fix: Replace with raise ValueError including the invalid ID and valid range in the error message.

2. Asset filename collision check — export_with_assets.py

File: dm_control/mjcf/export_with_assets.py:54

assert out_file_name not in assets guards against the output XML filename colliding with an existing asset. With -O, a collision would silently overwrite model data during MJCF export.

Fix: Replace with raise RuntimeError including the conflicting filename.

3. Mocap body name resolution — index.py

File: dm_control/mujoco/index.py:233

assert None not in mocap_body_names verifies all mocap body names were resolved from body_mocapid mappings. With -O, unresolved None values propagate into the name mapping, causing hard-to-diagnose errors downstream.

Fix: Replace with raise RuntimeError with a descriptive message.

Changes

File Change Lines
engine.py assertraise ValueError +8 / -4
export_with_assets.py assertraise RuntimeError +3 / -1
index.py assertraise RuntimeError +4 / -1

Total: 3 files, +15 / -6 lines

About This Review

This security audit was performed by UNA (Unified Nexus Agent), an autonomous AI security auditor — a Governed Digital Organism (GDO) designed and built by Tom Budd (tom@tombudd.com | tombudd.com).

UNA audits open-source codebases for security vulnerabilities, code quality issues, and reliability concerns. All findings are human-verified before submission.

Note: Happy to sign the Google CLA at cla.developers.google.com if required.

…port

Replace 6 bare assert statements with proper raise ValueError/RuntimeError
that persist when Python runs with -O (optimized mode):

1. dm_control/mujoco/engine.py — Camera.select():
   Replace 4 assert statements validating body_id, geom_id, flex_id,
   and skin_id bounds. These protect against out-of-bounds access to
   MuJoCo physics model data. With -O, invalid IDs would silently
   pass through and cause undefined behavior downstream.

2. dm_control/mjcf/export_with_assets.py — export_with_assets():
   Replace assert checking output filename doesn't collide with
   existing assets. With -O, a collision would silently overwrite
   model data during export.

3. dm_control/mujoco/index.py — _get_size_name_to_element_names():
   Replace assert verifying all mocap body names are resolved.
   With -O, None values could propagate into the name mapping,
   causing hard-to-diagnose errors in downstream code.

Reviewed-by: UNA-GDO sovereign-v2.0 (Autonomous Security Auditor)
Built-by: Tom Budd <tom@tombudd.com> — tombudd.com
@google-cla
Copy link

google-cla bot commented Mar 23, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant