Skip to content

Commit

Permalink
Fix for writing blobs with null bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mytherin committed Sep 3, 2024
1 parent eb5e479 commit a13f20e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/include/postgres_binary_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ class PostgresBinaryWriter {
}
}

void WriteRawBlob(string_t value) {
auto str_size = value.GetSize();
auto str_data = value.GetData();
WriteRawInteger<int32_t>(NumericCast<int32_t>(str_size));
stream.WriteData(const_data_ptr_cast(str_data), str_size);
}

void WriteVarchar(string_t value) {
auto str_size = value.GetSize();
auto str_data = value.GetData();
Expand All @@ -219,11 +226,10 @@ class PostgresBinaryWriter {
new_str += str_data[i];
}
}
WriteVarchar(new_str);
WriteRawBlob(new_str);
return;
}
WriteRawInteger<int32_t>(NumericCast<int32_t>(str_size));
stream.WriteData(const_data_ptr_cast(str_data), str_size);
WriteRawBlob(value);
}

void WriteArray(Vector &col, idx_t r, const vector<uint32_t> &dimensions, idx_t depth, uint32_t count) {
Expand Down Expand Up @@ -336,12 +342,16 @@ class PostgresBinaryWriter {
WriteUUID(data);
break;
}
case LogicalTypeId::BLOB:
case LogicalTypeId::VARCHAR: {
auto data = FlatVector::GetData<string_t>(col)[r];
WriteVarchar(data);
break;
}
case LogicalTypeId::BLOB: {
auto data = FlatVector::GetData<string_t>(col)[r];
WriteRawBlob(data);
break;
}
case LogicalTypeId::ENUM: {
idx_t pos;
switch (type.InternalType()) {
Expand Down

0 comments on commit a13f20e

Please sign in to comment.