Linguist: Fix out-of-bounds read when reading a QM file
loadQM() locates each message record through an offset read from the
file and then reads per-field lengths from within the message block,
advancing a pointer by those lengths. The length check done while
scanning the top-level blocks does not cover these inner offsets and
lengths, so a corrupted QM file with an out-of-range record offset or an
oversized field length makes the reader access memory past the end of
the file buffer. This crashes lconvert and Qt Linguist, or copies
adjacent process memory into the produced translation.
Track the size of the message block and reject record offsets outside
it, and check the number of available bytes before every tag, length
and payload read, failing with a format error otherwise.
Fixes: QTBUG-148061
Change-Id: Ifd9f9b27183bf0aee040577afd530a2b7f622d93
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>