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

JSON document does not report error even exceeds the maximum depth. #37292

Closed
Tracked by #36993
xiongjiwei opened this issue Aug 23, 2022 · 3 comments · Fixed by #37759
Closed
Tracked by #36993

JSON document does not report error even exceeds the maximum depth. #37292

xiongjiwei opened this issue Aug 23, 2022 · 3 comments · Fixed by #37759
Assignees
Labels
component/json severity/moderate type/bug The issue is confirmed as a bug.

Comments

@xiongjiwei
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

select json_valid(repeat('[', 1000));
Error 3157: The JSON document exceeds the maximum depth.

2. What did you expect to see? (Required)

Error 3157: The JSON document exceeds the maximum depth.

3. What did you see instead (Required)

0

4. What is your TiDB version? (Required)

@xiongjiwei xiongjiwei added type/bug The issue is confirmed as a bug. component/json labels Aug 23, 2022
@windtalker
Copy link
Contributor

There is a hard limit of max depth(100) of json type in MySQL, while TiDB does not have such limits, so TiDB does not throw error.
I think it should be a moderate or minor bug.

@YangKeao
Copy link
Member

See golang/go#31789

The standard library of golang has a default max depth for 10000, (but as I know, it doesn't provide a way to specify the depth). We can verify this limitation through:

In TiDB:

MySQL [test]> select json_valid(concat(repeat('[', 1001), repeat(']', 10001)));
+-----------------------------------------------------------+
| json_valid(concat(repeat('[', 1001), repeat(']', 10001))) |
+-----------------------------------------------------------+
|                                                         0 |
+-----------------------------------------------------------+
1 row in set (0.001 sec)

MySQL [test]> select json_valid(concat(repeat('[', 10001), repeat(']', 10001)));
+------------------------------------------------------------+
| json_valid(concat(repeat('[', 10001), repeat(']', 10001))) |
+------------------------------------------------------------+
|                                                          0 |
+------------------------------------------------------------+
1 row in set (0.001 sec)

See serde-rs/json#162

The default recursion depth used in TiKV is 128 (by default), which is so different from the TiDB. Also, it's not configurable, but this limitation can be turned off: https://docs.rs/serde_json/latest/serde_json/struct.Deserializer.html#method.disable_recursion_limit .

@YangKeao
Copy link
Member

We could handle this special error everywhere, if it's needed.

@YangKeao YangKeao self-assigned this Aug 25, 2022
@xiongjiwei xiongjiwei mentioned this issue Aug 30, 2022
34 tasks
@xiongjiwei xiongjiwei assigned xiongjiwei and unassigned YangKeao Sep 2, 2022
ti-chi-bot pushed a commit that referenced this issue Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/json severity/moderate type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants