JBIG2: finds end of a segment when length is not specified

Fixes #2139 and #1927