Missing validation in JSON constructors, LEFT expressions, and CH-block decoding

未关闭
#11,328 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@windtalker 已经在做这个了。

开始于 2026年11月16日。

  • #11329 来自 @windtalker —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
cpp
领域
backend, databases

调研方向

The report identifies three areas: JSON constructors, buildLeftUTF8Function, and CH-block decoding, including cached appends; it does not name source files or tests. Start by tracing those entry points and their existing error handling, then inspect related tests for JSON, LEFT expressions, and V0/V1/V2 decoding. Done means rejecting the described invalid inputs with the specified errors while preserving the valid cases; pull request #11329 is already open.

由索引模型根据 Issue 内容生成。

描述

type/bug

Bug Report

1. Minimal reproduce step (Required)

These are source-level reproduction scenarios; they were not executed locally.

  1. Pass a non-NULL, zero-byte binary JSON value to the internal json_array function, or as a value argument to json_object. These functions expect binary JSON, so this input represents an invalid binary JSON payload, not a valid JSON empty string. Both nullable and non-nullable execution branches construct JsonBinary using data_from.size - 1 without first checking that the input is nonempty.
  2. Build a scalar DAG expression with signature tipb::ScalarFuncSig::LeftUTF8 and zero children, or one valid string child, then analyze it with DAGExpressionAnalyzer::getActions. buildLeftUTF8Function reads children 0 and 1 without first checking their count. With more than two children, extra arguments are silently ignored.
  3. Decode a CH-block chunk declaring two rows and two UInt64 columns, but containing two values in the first column and only one value, or no values, in the last column. For V1/V2, keep the declared sub-block row count at two and compress the shortened raw payload so compression framing remains valid. Exercise both first-chunk decoding and appending after a valid cached chunk. A single-column chunk that provides fewer values than its declared row count exposes the same missing validation.
2. What did you expect to see? (Required)

Reject non-NULL empty binary JSON with BAD_ARGUMENTS, before reading its type byte or subtracting from its length. SQL NULL values should still become JSON null, correctly encoded JSON empty strings should remain valid, and json_object should continue to accept empty member names.

Reject LEFT expressions whose child count is not exactly two with an ordinary Coprocessor::BadRequest error before accessing any child. Preserve normal two-argument UTF-8 LEFT behavior.

Reject CH-block columns whose decoded row count does not match the declared count with an ordinary CANNOT_READ_ALL_DATA error before exposing the Block to downstream execution. Check each column and sub-block, accounting for rows accumulated from previous chunks. Preserve valid V0/V1/V2 decoding, compression, and cached appends.

3. What did you see instead (Required)

For empty binary JSON constructor values, the length subtraction wraps to SIZE_MAX. JsonBinary stores that length without validation; the array/object builders can pass it through VectorWriter::write to memcpy, potentially crashing TiFlash.

For LEFT expressions with fewer than two children, the analyzer indexes outside the protobuf repeated field, potentially crashing TiFlash. Extra children are ignored instead of being rejected.

For truncated CH-block columns, numeric bulk deserialization accepts short reads at EOF. The V0 and V1/V2 decode paths do not verify each column's actual resulting size, and Block::rows() only reports the first column's size. A Block whose first column has two rows and last column has one can therefore reach downstream vectorized code that assumes equal column lengths, potentially reading outside the shorter column's valid range. The same gap exists during cached appends.

These findings were confirmed by source inspection, without a local runtime reproduction.

4. What is your TiFlash version? (Required)

master at 1e98c8ec6627674d848132a8f81b79baec80a7ad.

主要语言
C++
星标
1k
派生
428
平均合并
2 天 7 小时
30 天内合并 PR
100

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

pingcap/tiflash 的其他 Issue

查看 pingcap/tiflash 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。