Skip to content
Closed
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
13 changes: 13 additions & 0 deletions be/src/util/jsonb_document.h
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,19 @@ struct ArrayVal : public ContainerVal {
inline Status JsonbDocument::checkAndCreateDocument(const char* pb, size_t size,
JsonbDocument** doc) {
*doc = nullptr;
// Fix Issue #58523: Tolerate empty data from legacy versions.
// If size is 0, we return a static valid "Null" document.
if (size == 0) {
// 手动构造一个合法的 Null 文档二进制数据
Copy link
Contributor

Choose a reason for hiding this comment

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

所有的注释都得使用英文。

// 第1个字节:Version = 1 (JSONB_VER)
// 第2个字节:Type = 0 (T_Null)
static char s_null_buf[] = {1, 0};
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. 在beut 里增加一个case,验证一下 这种构造方式构造出的jsonbdocument 的version = 1 and type = T NULL。防止未来有人重构代码,把jsonb的bytes 结构改乱了。
  2. 在beut 中还要验证一下把这个null jsonb document 转成一个bytes 数组,然后可以checkAndCreateDocument 再创建出这个null jsonb document。


// 将 doc 指向这个静态的内存区域
*doc = reinterpret_cast<JsonbDocument*>(s_null_buf);
return Status::OK();
}

if (!pb || size < sizeof(JsonbHeader) + sizeof(JsonbValue)) {
return Status::InvalidArgument("Invalid JSONB document: too small size({}) or null pointer",
size);
Expand Down