ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

unzcrash.c
Go to the documentation of this file.
00001 
00002 /* A test program written to test robustness to decompression of
00003    corrupted data.  Usage is 
00004        unzcrash filename
00005    and the program will read the specified file, compress it (in memory),
00006    and then repeatedly decompress it, each time with a different bit of
00007    the compressed data inverted, so as to test all possible one-bit errors.
00008    This should not cause any invalid memory accesses.  If it does, 
00009    I want to know about it!
00010 
00011    PS.  As you can see from the above description, the process is
00012    incredibly slow.  A file of size eg 5KB will cause it to run for
00013    many hours.
00014 */
00015 
00016 /* ------------------------------------------------------------------
00017    This file is part of bzip2/libbzip2, a program and library for
00018    lossless, block-sorting data compression.
00019 
00020    bzip2/libbzip2 version 1.0.6 of 6 September 2010
00021    Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org>
00022 
00023    Please read the WARNING, DISCLAIMER and PATENTS sections in the 
00024    README file.
00025 
00026    This program is released under the terms of the license contained
00027    in the file LICENSE.
00028    ------------------------------------------------------------------ */
00029 
00030 
00031 #include <stdio.h>
00032 #include <assert.h>
00033 #include "bzlib.h"
00034 
00035 #define M_BLOCK 1000000
00036 
00037 typedef unsigned char uchar;
00038 
00039 #define M_BLOCK_OUT (M_BLOCK + 1000000)
00040 uchar inbuf[M_BLOCK];
00041 uchar outbuf[M_BLOCK_OUT];
00042 uchar zbuf[M_BLOCK + 600 + (M_BLOCK / 100)];
00043 
00044 int nIn, nOut, nZ;
00045 
00046 static char *bzerrorstrings[] = {
00047        "OK"
00048       ,"SEQUENCE_ERROR"
00049       ,"PARAM_ERROR"
00050       ,"MEM_ERROR"
00051       ,"DATA_ERROR"
00052       ,"DATA_ERROR_MAGIC"
00053       ,"IO_ERROR"
00054       ,"UNEXPECTED_EOF"
00055       ,"OUTBUFF_FULL"
00056       ,"???"   /* for future */
00057       ,"???"   /* for future */
00058       ,"???"   /* for future */
00059       ,"???"   /* for future */
00060       ,"???"   /* for future */
00061       ,"???"   /* for future */
00062 };
00063 
00064 void flip_bit ( int bit )
00065 {
00066    int byteno = bit / 8;
00067    int bitno  = bit % 8;
00068    uchar mask = 1 << bitno;
00069    //fprintf ( stderr, "(byte %d  bit %d  mask %d)",
00070    //          byteno, bitno, (int)mask );
00071    zbuf[byteno] ^= mask;
00072 }
00073 
00074 int main ( int argc, char** argv )
00075 {
00076    FILE* f;
00077    int   r;
00078    int   bit;
00079    int   i;
00080 
00081    if (argc != 2) {
00082       fprintf ( stderr, "usage: unzcrash filename\n" );
00083       return 1;
00084    }
00085 
00086    f = fopen ( argv[1], "r" );
00087    if (!f) {
00088       fprintf ( stderr, "unzcrash: can't open %s\n", argv[1] );
00089       return 1;
00090    }
00091 
00092    nIn = fread ( inbuf, 1, M_BLOCK, f );
00093    fprintf ( stderr, "%d bytes read\n", nIn );
00094 
00095    nZ = M_BLOCK;
00096    r = BZ2_bzBuffToBuffCompress (
00097          zbuf, &nZ, inbuf, nIn, 9, 0, 30 );
00098 
00099    assert (r == BZ_OK);
00100    fprintf ( stderr, "%d after compression\n", nZ );
00101 
00102    for (bit = 0; bit < nZ*8; bit++) {
00103       fprintf ( stderr, "bit %d  ", bit );
00104       flip_bit ( bit );
00105       nOut = M_BLOCK_OUT;
00106       r = BZ2_bzBuffToBuffDecompress (
00107             outbuf, &nOut, zbuf, nZ, 0, 0 );
00108       fprintf ( stderr, " %d  %s ", r, bzerrorstrings[-r] );
00109 
00110       if (r != BZ_OK) {
00111          fprintf ( stderr, "\n" );
00112       } else {
00113          if (nOut != nIn) {
00114            fprintf(stderr, "nIn/nOut mismatch %d %d\n", nIn, nOut );
00115            return 1;
00116          } else {
00117            for (i = 0; i < nOut; i++)
00118              if (inbuf[i] != outbuf[i]) { 
00119                 fprintf(stderr, "mismatch at %d\n", i ); 
00120                 return 1; 
00121            }
00122            if (i == nOut) fprintf(stderr, "really ok!\n" );
00123          }
00124       }
00125 
00126       flip_bit ( bit );
00127    }
00128 
00129 #if 0
00130    assert (nOut == nIn);
00131    for (i = 0; i < nOut; i++) {
00132      if (inbuf[i] != outbuf[i]) {
00133         fprintf ( stderr, "difference at %d !\n", i );
00134         return 1;
00135      }
00136    }
00137 #endif
00138 
00139    fprintf ( stderr, "all ok\n" );
00140    return 0;
00141 }

Generated on Sat May 26 2012 04:32:19 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.