[Libpst-devel] lzfu_decompress

Nigel Horne njh at bandsman.co.uk
Wed Apr 26 09:41:34 UTC 2006


These patches fix all the valgrind overflow related problems I see. The
patches will need to be double checked first to ensure I haven't broken LZFU
inflation, but it looks fine to me.

There are three patches, lzfu.[ch] and readpst.c.

-Nigel Horne

*** Olzfu.c	Wed Apr 26 10:35:07 2006
--- lzfu.c	Wed Apr 26 10:35:38 2006
***************
*** 51,57 ****
      We always need to add 0x10 to the buffer offset because we need to skip past the header info
  */
  
! unsigned char* lzfu_decompress (unsigned char* rtfcomp) {
    // the dictionary buffer
    unsigned char dict[4096];
    // the dictionary pointer
--- 51,57 ----
      We always need to add 0x10 to the buffer offset because we need to skip past the header info
  */
  
! unsigned char* lzfu_decompress (unsigned char* rtfcomp, size_t *nbytes) {
    // the dictionary buffer
    unsigned char dict[4096];
    // the dictionary pointer
***************
*** 123,127 ****
--- 123,129 ----
    out_buf[out_ptr++] = '}';
    out_buf[out_ptr++] = '}';
    out_buf[out_ptr++] = '\0';
+ 	if(nbytes)
+ 		*nbytes = out_ptr;
    return out_buf;
  }


*** Olzfu.h	Wed Apr 26 10:36:06 2006
--- lzfu.h	Wed Nov 17 14:48:03 2004
***************
*** 1,4 ****
  #ifndef LZFU_H
  #define LZFU_H
! unsigned char* lzfu_decompress (unsigned char* rtfcomp, size_t *nbytes);
  #endif
--- 1,4 ----
  #ifndef LZFU_H
  #define LZFU_H
! unsigned char* lzfu_decompress (unsigned char* rtfcomp);
  #endif


*** Oreadpst.c	Wed Apr 26 10:36:12 2006
--- readpst.c	Wed Apr 26 10:37:17 2006
***************
*** 782,799 ****
  	attach_num = 0;
  
  	if (item->email->rtf_compressed != NULL) {
  	  DEBUG_MAIN(("Adding RTF body as attachment\n"));
  	  item->current_attach = (pst_item_attach*)xmalloc(sizeof(pst_item_attach));
  	  memset(item->current_attach, 0, sizeof(pst_item_attach));
  	  item->current_attach->next = item->attach;
  	  item->attach = item->current_attach;
! 	  item->current_attach->data = lzfu_decompress(item->email->rtf_compressed);
  	  item->current_attach->filename2 = xmalloc(strlen(RTF_ATTACH_NAME)+2);
  	  strcpy(item->current_attach->filename2, RTF_ATTACH_NAME);
  	  item->current_attach->mimetype = xmalloc(strlen(RTF_ATTACH_TYPE)+2);
  	  strcpy(item->current_attach->mimetype, RTF_ATTACH_TYPE);
! 	  memcpy(&(item->current_attach->size), item->email->rtf_compressed+sizeof(int32_t), sizeof(int32_t));
! 	  LE32_CPU(item->current_attach->size);
  	  //	  item->email->rtf_compressed = ;
  	  //	  attach_num++;
  	}
--- 782,802 ----
  	attach_num = 0;
  
  	if (item->email->rtf_compressed != NULL) {
+ 		size_t nbytes;
+ 
  	  DEBUG_MAIN(("Adding RTF body as attachment\n"));
  	  item->current_attach = (pst_item_attach*)xmalloc(sizeof(pst_item_attach));
  	  memset(item->current_attach, 0, sizeof(pst_item_attach));
  	  item->current_attach->next = item->attach;
  	  item->attach = item->current_attach;
! 	  item->current_attach->data = lzfu_decompress(item->email->rtf_compressed, &nbytes);
  	  item->current_attach->filename2 = xmalloc(strlen(RTF_ATTACH_NAME)+2);
  	  strcpy(item->current_attach->filename2, RTF_ATTACH_NAME);
  	  item->current_attach->mimetype = xmalloc(strlen(RTF_ATTACH_TYPE)+2);
  	  strcpy(item->current_attach->mimetype, RTF_ATTACH_TYPE);
! 	  /*memcpy(&(item->current_attach->size), item->email->rtf_compressed+sizeof(int32_t), sizeof(int32_t));
! 	  LE32_CPU(item->current_attach->size);*/
! 		item->current_attach->size = nbytes;
  	  //	  item->email->rtf_compressed = ;
  	  //	  attach_num++;
  	}



More information about the Libpst-devel mailing list