LZW: prevent reading beyond the end of the stream

Fixes #10525.