--- psiconv/trunk/lib/psiconv/parse_image.c 1999/10/11 15:06:57 10 +++ psiconv/trunk/lib/psiconv/parse_image.c 1999/10/11 16:15:14 12 @@ -23,14 +23,50 @@ #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; - psiconv_u32 size; - int leng; + int read_err = 0; + psiconv_u32 size,offset,picsize,temp,datasize,pixelnr,datanr; + psiconv_u8 marker; + int i; psiconv_progress(lev+1,off,"Going to read a paint data section"); (*result) = malloc(sizeof(**result)); @@ -47,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; @@ -62,7 +99,7 @@ picsize = (*result)->ysize * (*result)->xsize; - psiconv_progress("Going to read 6 unused longs"); + psiconv_progress(lev+2,off+len,"Going to read 6 unused longs"); for (i = 0 ; i < 6; i++) { temp = psiconv_read_u32(buf,lev+2,off+len); if (temp != 0x00) { @@ -70,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; } @@ -80,7 +118,7 @@ len = offset; datasize = size - len; - psiconv_progress(buf,lev+2,off+len,"Going to read the pixel data"); + psiconv_progress(lev+2,off+len,"Going to read the pixel data"); pixelnr = 0; datanr = 0; while ((datanr < datasize) && (pixelnr < picsize)) { @@ -98,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); @@ -129,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++) { @@ -154,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)