mitsuba-renderer / drjit

Dr.Jit — A Just-In-Time-Compiler for Differentiable Rendering
BSD 3-Clause "New" or "Revised" License
572 stars 40 forks source link

Fixed LoopOp out of bounds read with extra non-grad variables #281

Open DoeringChristian opened 5 days ago

DoeringChristian commented 5 days ago

When adding loop state variables to a differentiable LoopOp, and some of them do not have gradients attached, the grad_in_offset and might not correspond to the index in m_input_indices. When indexing into this array, using that index, an out-of-bounds access occurs.

I fixed this by adding another index grad_in_index to the Input struct that always tracks the index in m_input_indices, and can be used for indexing into that array.

It also fixes a reference counting bug, where ad variables in a suspended scope would be added to the loop state, and their count would be decremented when the temporary loop state arrays where freed.