This looks quite suspect to me. Why is data set to be the first element of data on each iteration of the loop?

    perl -e '$x=q{"}. "a"x10000 .q{"}; print "[$x,$x,$x]"' > test.json

generates a big enough file to make the `while (!feof...` loop run more than once. `cat test.json | ./jq .` works fine, `./jq --argfile foo test.json '$foo'` crashes.