--- psiconv/trunk/lib/psiconv/parse_image.c 1999/10/11 15:17:17 11 +++ psiconv/trunk/lib/psiconv/parse_image.c 1999/10/11 16:15:14 12 @@ -23,12 +23,47 @@ #include "data.h" #include "parse_routines.h" +int psiconv_parse_mbm_jumptable_section(const psiconv_buffer buf,int lev, + psiconv_u32 off, int *length, + psiconv_mbm_jumptable_section *result) +{ + int res = 0; + int len = 0; + psiconv_u32 listlen,temp; + int i; + + psiconv_progress(lev+1,off+len,"Going to read the mbm jumptable section"); + (*result) = psiconv_list_new(sizeof(psiconv_u32)); + + psiconv_progress(lev+2,off+len,"Going to read the list length"); + listlen = psiconv_read_u32(buf,lev+2,off+len); + psiconv_debug(lev+2,off+len,"List length: %08x",listlen); + len += 4; + + psiconv_progress(lev+2,off+len,"Going to read the list"); + for (i = 0; i < listlen; i++) { + temp = psiconv_read_u32(buf,lev+2,off+len); + psiconv_list_add(*result,&temp); + psiconv_debug(lev+3,off+len,"Offset: %08x",temp); + len += 4; + } + + if (length) + *length = len; + + psiconv_progress(lev+1,off+len-1,"End of mbm jumptable section " + "(total length: %08x", len); + + return res; +} + int psiconv_parse_paint_data_section(const psiconv_buffer buf,int lev, psiconv_u32 off, int *length, psiconv_paint_data_section *result) { int res = 0; int len = 0; + int read_err = 0; psiconv_u32 size,offset,picsize,temp,datasize,pixelnr,datanr; psiconv_u8 marker; int i; @@ -48,6 +83,7 @@ "Paint data section data offset has unexpected value"); psiconv_debug(lev+2,off+len, "Data offset: read %08x, expected %08x",offset,0x28); + res = -1; } len += 4; @@ -71,6 +107,7 @@ "Paint data section prologue has unknown values"); psiconv_debug(lev+2,off+len, "offset %02x: read %08x, expected %08x",i,temp,0x00); + res = -1; } len += 4; } @@ -99,6 +136,8 @@ "Picsize: %08x, Datasize: %08x, Pixelnr: %08x," "Datanr: %08x, marker: %02x",picsize,datasize,pixelnr, datanr,marker); + res = -1; + read_err = 1; } else { for (i = 0; i < 0x100-marker; i++) { temp = psiconv_read_u8(buf,lev+3,off+len+datanr+i); @@ -130,6 +169,8 @@ "Picsize: %08x, Datasize: %08x, Pixelnr: %08x," "Datanr: %08x, marker: %02x",picsize,datasize,pixelnr, datanr,marker); + res = -1; + read_err = 1; } else { temp = psiconv_read_u8(buf,lev+3,off+len+datanr); for (i = 0; i < marker; i++) { @@ -155,6 +196,14 @@ datanr += 1; } } + if (!read_err && ((datanr != datasize) || (pixelnr != picsize))) { + psiconv_warn(lev+2,off+len,"Corrupted picture data!"); + psiconv_debug(lev+3,off+len+datanr, + "Picsize: %08x, Datasize: %08x, Pixelnr: %08x," + "Datanr: %08x",picsize,datasize,pixelnr,datanr); + res = -1; + } + len += datanr; if (length)