Archived
util: the bounded read refuses before the tree exists
yy_convert enforced its value budget and depth bound in a second pass that ran only after every frame of the document had been collected into a scratch vector. The bound that promises a refused body has not grown memory grew its scratch with the body: a 200k-empty-array swarm counts no scalar at all, and the old code refused it after the whole swarm sat in the frame list. Both bounds are now enforced where a value is DISCOVERED -- every value counted, containers included, which is what the pre-migration parser callback counted and what the tests already pinned -- so a body past either bound ends the walk while the scratch is still budget-sized. What stays proportional to the body is yyjson's own read arena, capped by the byte bound at its open, and oai.cpp's comment now says exactly that. A json_test case carries the swarm.
This commit is contained in:
1 parent
7b9f33653f
commit
e46a8ba3d4
3 files changed
+47
-9
No files matched your search
@@ -387,6 +387,16 @@ TEST(json_parse_errors_and_bounds) {
|
||||
const Json ok = Json::parse_bounded("[[[1]]]", 100, 3, &over, &deep);
|
||||
CHECK(!over && !deep && ok.is_array());
|
||||
CHECK(Json::parse_bounded("{bad", 100, 3, &over, &deep).is_discarded());
|
||||
/* A refused body must be refused WITHOUT first collecting it: this swarm carries no scalar
|
||||
* at all, and the bounded read used to trip its budget in a second pass that ran only after
|
||||
* every frame of the document sat in a scratch vector -- the refusal grew memory with the
|
||||
* body, which is exactly what the bound promises against. Containers are values too. */
|
||||
std::string swarm = "[";
|
||||
for (int i = 0; i < 200000; ++i) swarm += "[],";
|
||||
swarm.back() = ']';
|
||||
over = deep = false;
|
||||
CHECK(Json::parse_bounded(swarm, 1000, 64, &over, &deep).is_discarded());
|
||||
CHECK(over && !deep);
|
||||
}
|
||||
|
||||
TEST(json_parse_duplicate_keys_and_large_flat_objects) {
|
||||
|
||||
Reference in new issue
Block a user