Fixes a logic bug I introduced as part of #4942. We were not handling the "read past EOF" case correctly, which caused requested_read_length to underflow in some cases. Also fixes a comparison (though this is unlikely to change anything).