This is an automated email from the ASF dual-hosted git repository. fgerlits pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
commit 0f50a5ab7cd9bcb2239099ebbd30d617ee54ac33 Author: Martin Zink <[email protected]> AuthorDate: Thu Feb 10 18:15:05 2022 +0100 MINIFICPP-1766 ProcessSession::read can't read zero length flowfiles (DatabaseContentRepository) Signed-off-by: Ferenc Gerlits <[email protected]> This closes #1273 --- extensions/rocksdb-repos/RocksDbStream.cpp | 3 +-- libminifi/test/rocksdb-tests/DBContentRepositoryTests.cpp | 8 ++++++-- libminifi/test/unit/ContentRepositoryDependentTests.h | 13 +++++++++++++ libminifi/test/unit/ProcessSessionTests.cpp | 5 +++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/extensions/rocksdb-repos/RocksDbStream.cpp b/extensions/rocksdb-repos/RocksDbStream.cpp index a1d67b9..fdfe7e0 100644 --- a/extensions/rocksdb-repos/RocksDbStream.cpp +++ b/extensions/rocksdb-repos/RocksDbStream.cpp @@ -56,8 +56,7 @@ size_t RocksDbStream::tell() const { size_t RocksDbStream::write(const uint8_t *value, size_t size) { if (!write_enable_) return STREAM_ERROR; - if (size == 0) return 0; - if (IsNullOrEmpty(value)) return STREAM_ERROR; + if (size != 0 && IsNullOrEmpty(value)) return STREAM_ERROR; auto opendb = db_->open(); if (!opendb) { return STREAM_ERROR; diff --git a/libminifi/test/rocksdb-tests/DBContentRepositoryTests.cpp b/libminifi/test/rocksdb-tests/DBContentRepositoryTests.cpp index e7f8d04..c74006f 100644 --- a/libminifi/test/rocksdb-tests/DBContentRepositoryTests.cpp +++ b/libminifi/test/rocksdb-tests/DBContentRepositoryTests.cpp @@ -228,13 +228,17 @@ TEST_CASE("Delete Remove Count Claim", "[TestDBCR5]") { REQUIRE(readstr == "well hello there"); } -TEST_CASE("ProcessSession::read reads the flowfile from offset to size", "[readoffsetsize]") { +TEST_CASE("ProcessSession::read reads the flowfile from offset to size (RocksDB)", "[readoffsetsize]") { ContentRepositoryDependentTests::testReadOnSmallerClonedFlowFiles(std::make_shared<core::repository::DatabaseContentRepository>()); } -TEST_CASE("ProcessSession::append should append to the flowfile and set its size correctly" "[appendsetsize]") { +TEST_CASE("ProcessSession::append should append to the flowfile and set its size correctly (RocksDB)" "[appendsetsize]") { ContentRepositoryDependentTests::testAppendToUnmanagedFlowFile(std::make_shared<core::repository::DatabaseContentRepository>()); ContentRepositoryDependentTests::testAppendToManagedFlowFile(std::make_shared<core::repository::DatabaseContentRepository>()); } + +TEST_CASE("ProcessSession::read can read zero length flowfiles without crash (RocksDB)", "[zerolengthread]") { + ContentRepositoryDependentTests::testReadFromZeroLengthFlowFile(std::make_shared<core::repository::DatabaseContentRepository>()); +} diff --git a/libminifi/test/unit/ContentRepositoryDependentTests.h b/libminifi/test/unit/ContentRepositoryDependentTests.h index cb4a940..49c735e 100644 --- a/libminifi/test/unit/ContentRepositoryDependentTests.h +++ b/libminifi/test/unit/ContentRepositoryDependentTests.h @@ -177,4 +177,17 @@ void testAppendToManagedFlowFile(std::shared_ptr<core::ContentRepository> conten CHECK(to_string(read_result) == "myfoobar"); CHECK(read_until_it_can_callback.value_ == "myfoobar"); } + +void testReadFromZeroLengthFlowFile(std::shared_ptr<core::ContentRepository> content_repo) { + Fixture fixture = Fixture(content_repo); + core::ProcessSession& process_session = fixture.processSession(); + const auto flow_file = process_session.create(); + REQUIRE(flow_file); + fixture.transferAndCommit(flow_file); + + CHECK(flow_file->getSize() == 0); + REQUIRE_NOTHROW(process_session.readBuffer(flow_file)); + ReadUntilItCan read_until_it_can_callback; + REQUIRE_NOTHROW(process_session.read(flow_file, &read_until_it_can_callback)); +} } // namespace ContentRepositoryDependentTests diff --git a/libminifi/test/unit/ProcessSessionTests.cpp b/libminifi/test/unit/ProcessSessionTests.cpp index 088be74..3cc9a24 100644 --- a/libminifi/test/unit/ProcessSessionTests.cpp +++ b/libminifi/test/unit/ProcessSessionTests.cpp @@ -110,3 +110,8 @@ TEST_CASE("ProcessSession::append should append to the flowfile and set its size ContentRepositoryDependentTests::testAppendToManagedFlowFile(std::make_shared<minifi::core::repository::VolatileContentRepository>()); ContentRepositoryDependentTests::testAppendToManagedFlowFile(std::make_shared<minifi::core::repository::FileSystemRepository>()); } + +TEST_CASE("ProcessSession::read can read zero length flowfiles without crash", "[zerolengthread]") { + ContentRepositoryDependentTests::testReadFromZeroLengthFlowFile(std::make_shared<core::repository::VolatileContentRepository>()); + ContentRepositoryDependentTests::testReadFromZeroLengthFlowFile(std::make_shared<core::repository::FileSystemRepository>()); +}
