Skip to content

StorageFactory::open_read_write does not perform validation for empty paths #2255

@zhihaoshang

Description

@zhihaoshang

Description

When opening storage using StorageFactory::open_read_write(), if the storage_options.uri passed in is an empty string, the current implementation does not throw an exception. Instead, it interprets the empty path as "." and continues to open the storage plugin normally.

Expected Behavior

Throws an exception when the string is empty

Actual Behavior

No exception thrown

To Reproduce

Test Case

#include <gtest/gtest.h>
#include <memory>
#include <string>
#include "rosbag2_storage/storage_interfaces/read_only_interface.hpp"
#include "rosbag2_storage/storage_interfaces/read_write_interface.hpp"
#include "rosbag2_storage/storage_factory.hpp"
#include "test_constants.hpp"

using rosbag2_storage::storage_interfaces::ReadWriteInterface;
using rosbag2_storage::storage_interfaces::ReadOnlyInterface;

// The fixture for testing class Foo.
class StorageFactoryTest : public ::testing::Test
{
public:
  rosbag2_storage::StorageFactory factory;
  std::string bag_file_path = "path/to/be/loaded.bag";
  std::string test_unavailable_plugin_id = "my_unavailable_plugin";
};

TEST_F(StorageFactoryTest, test) {
  EXPECT_THROW(
    factory.open_read_write({"", test_constants::READ_WRITE_PLUGIN_IDENTIFIER}),
    std::runtime_error);
}

Output

 RUN      ] StorageFactoryTest.test
opening testplugin read write: storage uri: .
config file uri: .

closing.
/home/shangzh/rosbag2_ws/rosbag2/rosbag2_storage/test/rosbag2_storage/test_storage_factory.cpp:22: Failure
Expected: factory.open_read_write({"", test_constants::READ_WRITE_PLUGIN_IDENTIFIER}) throws an exception of type std::runtime_error.
  Actual: it throws nothing.

[  FAILED  ] StorageFactoryTest.test (19 ms)
[----------] 1 test from StorageFactoryTest (19 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (19 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] StorageFactoryTest.test

 1 FAILED TEST

System (please complete the following information)

OS: ubuntu 24.04
ROS 2 Distro: ros 2 jazzy
Install Method: source
Version: ros 2 jazzy
build options: --mixin asan-gcc

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmore-information-neededFurther information is required

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions