NXP-14194: fix infinite loop on unexpected end of stream