

**Patch 4:**

The fourth patch uses a `for` loop to iterate over the valid bytes to copy, ensuring that the loop doesn't go out of bounds.

