Several bug fixes in img_io.c

I did encounter a segfault today in the tsk/img/img_io.c code, line 175 failing due to len2 containing a negative value. This CL is a patch up, but the file needs some careful reviewing by the original author.