Skip to content

Deep nesting produces <skipped: too deep> artifacts in printing output #3413

@ishnagy

Description

@ishnagy

Describe the bug
MAX_PARSING_DEPTH in src/jv_parse.c was recently increased from 256 to 10000 in #3328 , but the corresponding MAX_PRINT_DEPTH in src/jv_print.c was left untouched. Now jq does not fail out on parsing structures deeper than 256 anymore, but it produces invalid json when printing them, inserting the <skipped: too deep> literal into the output.

I think the problem is MAX_PRINT_DEPTH not being in sync with MAX_PARSING_DEPTH, ideally they should both change together.

To Reproduce

(
    for i in {0..256}; do echo -n '{"k'$i'":'; done
    echo -n '"VALUE"';
    for i in {0..256}; do echo -n '}'; done
) > print_depth_repro.256.json

print_depth_repro.256.json

$ cat print_depth_repro.256.json | cut -c1939-1954
{"k256":"VALUE"}

$ cat print_depth_repro.256.json | jq -c | jq
jq: parse error: Invalid numeric literal at line 1, column 1955

$ cat print_depth_repro.256.json | jq -c | cut -c1939-1966
{"k256":<skipped: too deep>}

Expected behavior
JSON data that can be parsed without error, should be possible to print out in a valid form as well.

Environment (please complete the following information):

  • OS and Version: macOS/Linux (it really doesn't matter)
  • jq version 1.8.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions