Skip to content
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

libvips segfault during mapim with bicubic interpolation #1180

Closed
erdmann opened this issue Dec 16, 2018 · 10 comments
Closed

libvips segfault during mapim with bicubic interpolation #1180

erdmann opened this issue Dec 16, 2018 · 10 comments

Comments

@erdmann
Copy link

erdmann commented Dec 16, 2018

Hi John,

I'm finding that libvips is segfaulting whenever it performs mapim using bicubic interpolation. Here is a demonstration using a debug build from tag v8.7.2 (though the problem seems to go back a few versions):

$ vips --version
vips-8.7.2-Sun Dec 16 08:18:04 UTC 2018

$ vips black im.v 100 100
memory: high-water mark 16.09 KB

$ vips xyz coords.v 100 100
memory: high-water mark 143.86 KB

$ vips mapim im.v im2_linear.v coords.v
memory: high-water mark 29.54 KB

$ vips mapim im.v im2_cubic.v coords.v --interpolate=bicubic
**
VIPS:ERROR:bicubic.cpp:536:void vips_interpolate_bicubic_interpolate(VipsInterpolate*, void*, VipsRegion*, double, double): assertion failed: (ix - 1 >= in->valid.left)
Aborted

Many thanks in advance for having a look!

@jcupitt
Copy link
Member

jcupitt commented Dec 16, 2018

Oh dear, that's bad. I guess there's an off-by-one problem somewhere.

It seems to work in 8.8, I'll try 8.7. I don't remember touching any of that code, funny.

@jcupitt
Copy link
Member

jcupitt commented Dec 16, 2018

Duh I had DEBUG off. With it on, I see the assert fail on 8.8 as well. Thanks for the great report, I'll investigate.

@erdmann
Copy link
Author

erdmann commented Dec 16, 2018

As an additional piece of information, it looks like it applies to the other interpolation types, too, suggesting that it might have something to do with boundary conditions when kernel footprint steps outside of the image.

$ vips --version
vips-8.8.0-Sun Dec 16 10:26:51 UTC 2018
memory: high-water mark 0 bytes

$ vips mapim im.v im2_cubic.v coords.v --interpolate=bicubic
**
VIPS:ERROR:bicubic.cpp:536:void vips_interpolate_bicubic_interpolate(VipsInterpolate*, void*, VipsRegion*, double, double): assertion failed: (ix - 1 >= in->valid.left)
Aborted

$ vips mapim im.v im2_nohalo.v coords.v --interpolate=nohalo
**
VIPS:ERROR:nohalo.cpp:1524:void vips_interpolate_nohalo_interpolate(VipsInterpolate*, void*, VipsRegion*, double, double): assertion failed: (ix - 2 >= in->valid.left)
Aborted

$ vips mapim im.v im2_vsqbs.v coords.v --interpolate=vsqbs
**
VIPS:ERROR:vsqbs.cpp:344:void vips_interpolate_vsqbs_interpolate(VipsInterpolate*, void*, VipsRegion*, double, double): assertion failed: (ix - 1 >= in->valid.left)
Aborted

$ vips mapim im.v im2_lbb.v coords.v --interpolate=lbb
**
VIPS:ERROR:lbb.cpp:803:void vips_interpolate_lbb_interpolate(VipsInterpolate*, void*, VipsRegion*, double, double): assertion failed: (ix - 1 >= in->valid.left)
Aborted

Thanks again!

jcupitt added a commit that referenced this issue Dec 17, 2018
pixels were not being offset by the stencil origin, so interpolators
like bicubic could fail

thanks @erdmann

#1180
@jcupitt
Copy link
Member

jcupitt commented Dec 17, 2018

OK, fixed in git master plus the head of the 8.7 branch. Thank you very much for finding this awful problem @erdmann !

I'll wait a few days before pushing out 8.7.4, in case anything else comes up.

@kleisauke
Copy link
Member

I think this should land in 8.7.3 (instead than 8.7.4) because 8.7.3 isn't released yet.

@jcupitt
Copy link
Member

jcupitt commented Dec 17, 2018

Yes, I goofed. I've moved it back to 8.7.3.

@erdmann
Copy link
Author

erdmann commented Dec 17, 2018

Hi John,

Thanks for the very fast response. This seems to solve the segfault problem, but I now get artifacts along the right and bottom edges of the image using cubic interpolation. I'm expecting that when I do mapim using an identity mapping, I'll get an identical image to the input, and that's true when I use linear interpolation, but it's not true with bicubic interpolation. With bicubic, the bottom row and right column are difference.

Here is a demonstration of the issue:

$ vips --version
vips-8.8.0-Mon Dec 17 18:06:08 UTC 2018
memory: high-water mark 0 bytes

$ convert logo: logo.tif # make a non-trivial image using imagemagick

$ vipsheader logo.tif 
logo.tif: 640x480 uchar, 3 bands, srgb, tiffload
memory: high-water mark 0 bytes

$ vips xyz coords.v 640 480
memory: high-water mark 3.28 MB

$ vips mapim logo.tif logo_linear.v coords.v 
memory: high-water mark 3.80 MB

$ vips subtract logo.tif logo_linear.v difference_linear.v
memory: high-water mark 2.81 MB

$ vips min difference_linear.v
0.000000
memory: high-water mark 90.38 KB

$ vips max difference_linear.v
0.000000
memory: high-water mark 90.38 KB

$ vips mapim logo.tif logo_cubic.v coords.v --interpolate=bicubic
memory: high-water mark 3.80 MB

$ vips subtract logo.tif logo_cubic.v difference_cubic.v
memory: high-water mark 2.81 MB

$ vips max difference_cubic.v # problem is here
255.000000
memory: high-water mark 90.38 KB

$ vips min difference_cubic.v 
0.000000
memory: high-water mark 90.38 KB

# remove the bottom row and right column
$ vips crop difference_cubic.v difference_cubic_upper_left.v 0 0 639 479 
memory: high-water mark 1.80 MB

$ vips min difference_cubic_upper_left.v 
0.000000
memory: high-water mark 90.23 KB

$ vips max difference_cubic_upper_left.v 
0.000000
memory: high-water mark 90.23 KB

Thanks again!

@erdmann erdmann closed this as completed Dec 17, 2018
@erdmann erdmann reopened this Dec 17, 2018
@erdmann
Copy link
Author

erdmann commented Dec 17, 2018

Sorry, accidentally closed.

jcupitt added a commit that referenced this issue Dec 17, 2018
we had the clip in the wrong place

see #1180
@jcupitt
Copy link
Member

jcupitt commented Dec 17, 2018

You're right, the clip was in the wrong place. I improved the test as well. Could you test again, please?

@erdmann
Copy link
Author

erdmann commented Dec 17, 2018

Looks great! All of my personal tests pass (tested on master). Thanks again.

@erdmann erdmann closed this as completed Dec 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants