Handle read(n) returning nil

Fixes #33090.