ANI validation improvements
- Reject files with multiple
anih
chunks. Ananih
chunk causes us to initialize a bunch of state, which we only expect to do once per file. Fixes #202 (closed). - Reject files with multiple
INAM
orIART
chunks. These would cause memory leaks otherwise. - Validate
anih
chunk size. Before reading a chunk, we verify that enough bytes are available to match the chunk size declared by the file. However, uniquely, theanih
chunk loader doesn't verify that this size matches the number of bytes it actually intends to read. Thus, if the chunk size is too small and the file ends in the middle of the chunk, we populate some context fields with stack garbage. (But we'd still fail later on because the file doesn't contain any images.) Fix this.