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

Segmentation Fault when adding an empty list of vehicles #118

Open
jorchube opened this issue Nov 11, 2024 · 4 comments
Open

Segmentation Fault when adding an empty list of vehicles #118

jorchube opened this issue Nov 11, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@jorchube
Copy link

jorchube commented Nov 11, 2024

Hello,

When setting an empty list of vehicles pyvroom the python process crashes with a Segmentation Fault.

Setting an empty list of vehicles for the problem instance is obviously not what anyone would intend to do and is something that one might want to detect early in its logic, but it may be inviable to anticipate what other scenarios end up triggering a segfault.

Nevertheless, a segmentation fault in the python process itself is something that code making use of pyvroom can not defent itself against or recover from, is fairly unexpected and is something that makes detecting and debugging the actual issue much harder.

It would be a great improvement even just throwing a generic RuntimeError.

Here is a minimal code reproducing the segfault with pyvroom version 1.14.0 on Ubuntu (kernel 6.5.0) aarch64:

def segfault_poc():
    problem_instance = vroom.Input()
    job = vroom.Job(
        1,
        location=1,
        time_windows=[vroom.TimeWindow(start=0, end=3600)],
        service=1,
    )
    problem_instance.set_durations_matrix(
        profile="car",
        matrix_input=[[0, 100], [100, 0]],
    )
    problem_instance.add_job(job)
    problem_instance.add_vehicle([])
    problem_instance.solve(exploration_level=5, nb_threads=4)

Thank you very much for your work

@jonathf
Copy link
Collaborator

jonathf commented Nov 11, 2024

I agree that isn't ideal.

@jcoupey, I assume that throwing an exception if there are no vehicles is best added upstream vroom. If not, I can easily add on in the Python layer alone.

@jcoupey
Copy link
Contributor

jcoupey commented Nov 11, 2024

Thanks for reporting.

    problem_instance.add_job(job)
    problem_instance.add_vehicle([])

Looks like you're assigning an empty array as a vehicle, which is different than having an empty list of vehicles. Anyway it turns out that both situations are handled upstream when using json input:

$ vroom '{"vehicles":[],"jobs":[{"id":1,"location_index":1}],"matrices":{"car":{"durations":[[0,100],[100,0]]}}}'
[Error] Invalid vehicles.
{"code":2,"error":"Invalid vehicles."}
$ vroom '{"vehicles":[[]],"jobs":[{"id":1,"location_index":1}],"matrices":{"car":{"durations":[[0,100],[100,0]]}}}'
[Error] Invalid vehicle.
{"code":2,"error":"Invalid vehicle."}

but not when using the C++ API. I opened VROOM-Project/vroom#1187 upstream to track this.

@jcoupey jcoupey added the bug Something isn't working label Nov 11, 2024
@jcoupey
Copy link
Contributor

jcoupey commented Nov 14, 2024

I opened VROOM-Project/vroom#1187 upstream to track this.

Fixed in VROOM-Project/vroom#1190.

@jonathf
Copy link
Collaborator

jonathf commented Nov 20, 2024

I am looking at updating pyvroom now, but see that there are a few other updates upstream as well that also needs to be accommodated for. I will get to it when I have time. My schedule is quite filled these days, so please be patient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants