-
Notifications
You must be signed in to change notification settings - Fork 7
Guard against segfaults due to missing Vips.init() call (fixes #175) #176
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
base: main
Are you sure you want to change the base?
Conversation
…e#175) This adds a check to `VipsInvoker` that verifies that `Vips.init` was called before calling into libvips. This prevents users from running into segmentation faults (which is what happens at the moment if users forget to call `Vips.init`) and provides a better developer experience.
Let me have a think about this one - I'm not sure it's unreasonable for users to use the init method in libvips itself (via VipsHelper for example). There might still be a way to improve the developer experience by asking libvips itself if it's initialised, in VipsInvoker, and then set an |
@jbaiter Do you remember which function specifically caused the segfault, when |
It was in vips_foreign_load. I don't remember the specifics, but the list of modules was a nullpointer, iirc, and that caused the segmentation fault. There was a gobject warning as well. I'll give you a reproduction when the kids are asleep 😅 |
No rush! I was more wondering what you did in vips-ffm that triggered the segfault, so I can write a sample for it. |
It's pretty easy to reproduce, just call import app.photofox.vipsffm.VImage;
import app.photofox.vipsffm.Vips;
public class VipsDebug {
public static void main(String[] args) {
if (args.length != 1) {
System.err.println("usage: java -jar vips-dbg.jar <filename>");
}
Vips.run(arena ->
VImage.newFromFile(arena, args[0]).writeToFile("out-ffm.png")
);
}
}
|
I wanted to double check this behaviour upstream, so asked a question of the team: libvips/libvips#4642 |
So I checked the libvips API, and what But how about:
|
I got some advice from the upstream maintainers - other bindings call init on the callers behalf when they first load the module. That's not possible (or desirable, I think) with Java, but vips-ffm does have So Vips.run first tries to initialise, if that hasn't already been done, and skips if it has. |
👍🏾 so:
|
I think that we may not need the Unsure about the check in |
Hm, the README currently only suggests But I think, if the documentation stated more clearly that users either need to use I think my problem was that the need for But then again, simply forgetting to call an initialization method shouldn't result in a Java library crashing the JVM if you ask me 😅 Two ways out of that that come to mind:
|
I've been contemplating whether having a static initialiser kick off a |
This adds a check to
VipsInvoker
that verifies thatVips.init
was called before calling into libvips. This prevents users from running into segmentation faults (which is what happens at the moment if users forget to callVips.init
) and provides a better developer experience.