LZW: prevent reading beyond the end of the stream

Fixes #10525.
Merge pull request #431 from melissalinkert/rebased/develop/10525

LZW: prevent reading beyond the end of the stream (rebased onto develop)