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

Throw copy exception on invalid utf8 string #2208

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dataset/copy-fault-tests/invalid-utf8/schema.cypher
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create node table person (ID STRING, PRIMARY KEY (ID));
4 changes: 4 additions & 0 deletions src/processor/operator/persistent/reader/csv/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "processor/operator/persistent/reader/csv/parallel_csv_reader.h"
#include "processor/operator/persistent/reader/csv/serial_csv_reader.h"
#include "storage/store/table_copy_utils.h"
#include "utf8proc_wrapper.h"

using namespace kuzu::common;

Expand Down Expand Up @@ -340,6 +341,9 @@ void copyStringToVector(ValueVector* vector, uint64_t rowToAdd, std::string_view
vector, rowToAdd, reinterpret_cast<char*>(blobBuffer.get()), blobLen);
} break;
case LogicalTypeID::STRING: {
if (!utf8proc::Utf8Proc::isValid(strVal.data(), strVal.length())) {
throw common::CopyException{"Invalid UTF8-encoded string."};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also print the strVal in error message?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think printing the invalid utf8 characters is undefined behaviour and causes problems when writing the exception test for utf8 strings.

}
StringVector::addString(vector, rowToAdd, strVal.data(), strVal.length());
} break;
case LogicalTypeID::DATE: {
Expand Down
9 changes: 9 additions & 0 deletions test/test_files/exceptions/copy/invalid_utf8.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-GROUP CopyInvalidUTF8
-DATASET CSV copy-fault-tests/invalid-utf8

--

-CASE InvalidUTF8
-STATEMENT COPY person FROM "${KUZU_ROOT_DIRECTORY}/dataset/copy-fault-tests/invalid-utf8/invalid-utf8.csv"
---- error
Copy exception: Invalid UTF8-encoded string.
9 changes: 0 additions & 9 deletions test/test_files/exceptions/runtime/invalid_utf8.test

This file was deleted.