Skip to content

heifsave: clip out of range values when packing 16-bit to 8-bit #4524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2025

Conversation

kleisauke
Copy link
Member

@kleisauke kleisauke commented May 19, 2025

Test case:

$ cat <<EOT > sharpen-mild.mat
3 3 24
-1 -1 -1
-1 32 -1
-1 -1 -1
EOT
$ vips convf x.jpg x.avif sharpen-mild.mat

Where x.jpg is the image mentioned at lovell/sharp#4344 (comment).

Note that this only reproduces on the master branch when applying the following patch:

--- a/libvips/foreign/foreign.c
+++ b/libvips/foreign/foreign.c
@@ -1529,6 +1529,8 @@ vips__foreign_convert_saveable(VipsImage *in, VipsImage **ready,
 	VipsForeignSaveable saveable, VipsBandFormat *format, VipsCoding *coding,
 	VipsArrayDouble *background)
 {
+	VipsBandFormat original_format = in->BandFmt;
+
 	VipsImage *out;
 
 	/* in holds a reference to the output of our chain as we build it.
@@ -1642,7 +1644,7 @@ vips__foreign_convert_saveable(VipsImage *in, VipsImage **ready,
 	/* Convert to the format the saver likes.
 	 */
 	if (in->Coding == VIPS_CODING_NONE) {
-		if (vips_cast(in, &out, format[in->BandFmt], NULL)) {
+		if (vips_cast(in, &out, format[original_format], NULL)) {
 			g_object_unref(in);
 			return -1;
 		}

or when checking out a commit prior to 9f590ce. Otherwise, the image is cast to uchar just before writing.

(To simplify testing, this PR is rebased upon d87f9ed)

@kleisauke kleisauke force-pushed the heifsave-clip-ushort branch from 6a800cc to de23de1 Compare May 20, 2025 07:53
@kleisauke kleisauke changed the title heifsave: clip out of range values for 16-bit input to 8-bit output heifsave: clip out of range values when packing 16-bit to 8-bit May 20, 2025
@jcupitt jcupitt merged commit 05e2c5a into libvips:master May 20, 2025
6 checks passed
@kleisauke kleisauke deleted the heifsave-clip-ushort branch May 20, 2025 13:00
@adityapatadia
Copy link

Is there a plan to release 8.16.2, or will this be in 8.17?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants