gazebosim / gz-common

An audio-visual library supports processing audio and video files, a graphics library can load a variety 3D mesh file formats into a generic in-memory representation, and the core library of Gazebo Common contains functionality that spans Base64 encoding/decoding to thread pools.
https://gazebosim.org
Apache License 2.0
16 stars 40 forks source link

Fix crash when calling absPath with empty input #620

Closed gzfuzz closed 3 months ago

gzfuzz commented 3 months ago

🦟 Bug fix

Fixes #614

Summary

The current version of common::absPath may cause crash when calling the /gazebo/resource_paths/resolve service with empty request. By changing filesystem::absolute to the non-throwing version, and check the error_code accordingly, the crash could be avoided.

Checklist

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

πŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”ΈπŸ”Έ

gzfuzz commented 3 months ago

It seems that fs::absolute("", ec) behaves differently on Ubuntu ("" with error code) and macOS (cwd() without error code?)... Should empty input be treated as a special case?

iche033 commented 3 months ago

from https://en.cppreference.com/w/cpp/filesystem/absolute:

For POSIX-based operating systems, std::filesystem::absolute(p) is equivalent to std::filesystem::current_path() / p except for when p is the empty path.

Doesn't really says what the expected result is if p is empty. Likely just OS dependent. I lean towards adding a special #ifdef __APPLE__ check in the test.