ros-perception / image_transport_plugins

A set of plugins for publishing and subscribing to sensor_msgs/Image topics in representations other than raw pixel data.
BSD 3-Clause "New" or "Revised" License
55 stars 120 forks source link

Added basic input checking for RVL #137

Closed peci1 closed 1 year ago

peci1 commented 1 year ago

RVL blindly reads the first 8 bytes of the image and interprets them as image dimensions. I've just added a simple sanity check that can prevent some segfaults in case malformed data are passed.

peci1 commented 1 year ago

I haven't added a test to this repo, but I have tests elsewhere:

  1. [Correct case] Compress & decompress 2x2 32FC1 as RVL: https://github.com/ctu-vras/ros-utils/blob/1cba7f8d3515fbec7f65103522ac66a58740b0ee/image_transport_codecs/test/test_codecs.cpp#L242
  2. [Correct case] Compress & decompress 2x2 16UC1 as RVL: https://github.com/ctu-vras/ros-utils/blob/1cba7f8d3515fbec7f65103522ac66a58740b0ee/image_transport_codecs/test/test_codecs.cpp#L285
  3. [Correct case] Compress & decompress 640x480 as RVL: https://github.com/ctu-vras/ros-utils/blob/1cba7f8d3515fbec7f65103522ac66a58740b0ee/image_transport_codecs/test/test_codecs.cpp#L533
  4. [Fail case] Try to decompress a JPEG as RVL: https://github.com/ctu-vras/ros-utils/blob/1cba7f8d3515fbec7f65103522ac66a58740b0ee/image_transport_codecs/test/test_codecs.cpp#L411

This PR correctly prevents a segfault in 4., while keeping 1., 2. and 3. valid.

ijnek commented 1 year ago

@Mergifyio backport melodic-devel

mergify[bot] commented 1 year ago

backport melodic-devel

✅ Backports have been created

* [#139 Added basic input checking for RVL (backport #137)](https://github.com/ros-perception/image_transport_plugins/pull/139) has been created for branch `melodic-devel`