T09 · Insecure Skill Coding Practices
- Location
scripts/remove_watermark.py:74- Finding
Missing Lower-Bound Coordinate Validation Permits Image Corruption and Denial of Service
- Content
View full analysis
= height or px >= width: continue raw_alpha = alpha_map[y, x] ``` The affected coordinates are subsequently used without lower-bound validation: ```python watermarked = img_array[py, px, c] ``` ### Technical Analysis The watermark position is calculated by subtracting the configured watermark size and margins from the input image dimensions. For images smaller than the required watermark region, either `wm_x` or `wm_y` becomes negative. The validation only checks whether coordinates exceed the upper image bounds: ```python if py >= height or px >= width: continue ``` It does not verify that `px` and `py` are greater than or equal to zero. NumPy treats some negative indices as offsets from the end of an array. Consequently, valid negative indices can modify pixels on the opposite side of the image. If a negative index exceeds the array dimensions, NumPy raises an `IndexError`, terminating processing. ### Attack Path 1. An attacker supplies an image whose width or height is below the configured 80-pixel minimum implied by the 48-pixel watermark and 32-pixel margin. 2. The script calculates a negative `wm_x` or `wm_y`. 3. The processing loop passes the negative coordinates to the NumPy array because only upper bound ...[truncated 842 chars]- Remediation
View remediation
