Skip to content

Instantly share code, notes, and snippets.

@nilium
Last active April 10, 2020 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nilium/9d3102703cfa2b2716e1b9a9b64c2799 to your computer and use it in GitHub Desktop.
Save nilium/9d3102703cfa2b2716e1b9a9b64c2799 to your computer and use it in GitHub Desktop.
Possible bug in jq
$ jq -r '("\(tojson)\n" | . * 3)' sample.json
{"_id":"5e90d3f625fbeb699d799402...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................TOOLONG"}
{"_id":"5e90d3f625fbeb699d799402...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................TOOLONG"}
25fbeb699d799402...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................TOOLONG"}
$ jq -r '((tojson | "\(.)\n") | . * 5)' sample.json
{"_id":"5e90d3f625fbeb699d799402...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................TOOLONG"}
{"_id":"5e90d3f625fbeb699d799402...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................TOOLONG"}
25fbeb699d799402...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................TOOLONG"}
25fbeb699d799402...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................TOOLONG"}
@etU@etU25fbeb699d799402...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................TOOLONG"}

Only occurs when multiplying a string with an interpolation containing a suffix (i.e., the "\n"). Doesn't matter what the suffix is, does not seem to result in any difference for how many bytes are taken from the start of the third duplication.

The third entry onward in a string multiplication is missing 16 bytes, which have been replaced with NULs.

If the interpolation is instead a prefix, nothing incorrect happens.

Using concatenation instead of interpolation also works correctly.

In the second case, if using . in the interpolation instead of tojson, corruption of the string content occurs. If multiplied by 6 or more, the corruption seems to be stable, but doesn't appear to have any rhyme or reason to the content of the 16 bytes.

{"_id":"5e90d3f625fbeb699d799402...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................TOOLONG"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment