Validate shift bit depths in `png_set_shift` to prevent infinite loop

The function `png_set_shift` did not validate the `png_color_8` fields.
When any channel's bit depth was 0, `png_do_shift` entered an infinite
loop because the decrement `j -= 0` never changed `j`. Values exceeding
the image bit depth also produced incorrect shift arithmetic.

In contrast, the read-side sBIT chunk parser (i.e., `png_handle_sBIT`
in pngrutil.c) already rejects out-of-range values.

This commit adds equivalent per-channel validation on the write side,
ensuring that all relevant fields are in range from 1 to `bit_depth`,
and reporting invalid values via `png_app_error`.

Fixes pnggroup/libpng#804

This is a cherry-pick of commit 203c843cd732f7062798dfadcaa48dd13d4854af
from branch 'libpng18'.

Co-authored-by: Cosmin Truta <ctruta@gmail.com>
Signed-off-by: Cosmin Truta <ctruta@gmail.com>
1 file changed