Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 2024-06-25 - [Logic Bug DoS via Return Statement]
**Vulnerability:** A `return;` statement within the ECS system `car_nn_controlled_system`'s query iteration loop halted the entire system for all entities as soon as one car had an empty `ray_inputs` array.
**Learning:** In Bevy (and other ECS frameworks), using `return` inside a `Query::iter_mut()` loop exits the system function completely. This causes a single entity's invalid state to inflict a Denial of Service on all other entities processed by that system.
**Prevention:** Use `continue;` to safely skip the current iteration/entity and proceed to process the remaining entities. Always ensure loops handling multiple entities do not break/return prematurely due to one entity's missing state.
8 changes: 4 additions & 4 deletions src/car.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,19 @@ fn car_nn_controlled_system(
if brain.ray_inputs.is_empty() {
speed.0 = 0.0;
turn_speed.0 = 0.0;
return;
continue;
}

brain.nn_outputs = brain.nn.predict(&brain.ray_inputs);
let nn_out = brain.nn_outputs.last().unwrap().clone();
// nn_out = brain.nn.predict(&brain.ray_inputs).pop().unwrap();

let w_key = nn_out[0] >= NN_W_ACTIVATION_THRESHOLD;
let s_key = nn_out[2] >= NN_S_ACTIVATION_THRESHOLD;
let w_key = nn_out.get(0).copied().unwrap_or(0.0) >= NN_W_ACTIVATION_THRESHOLD;
let s_key = nn_out.get(2).copied().unwrap_or(0.0) >= NN_S_ACTIVATION_THRESHOLD;
let mut a_key = false;
let mut d_key = false;

if nn_out[1] >= 0.5 {
if nn_out.get(1).copied().unwrap_or(0.0) >= 0.5 {
a_key = true;
} else {
d_key = true;
Expand Down
Loading