~ubuntu-branches/ubuntu/utopic/foremost/utopic-proposed

« back to all changes in this revision

Viewing changes to extract.c

  • Committer: Bazaar Package Importer
  • Author(s): Gürkan Sengün
  • Date: 2008-05-20 09:31:54 UTC
  • mfrom: (1.2.2 upstream) (2.1.6 hardy)
  • Revision ID: james.westby@ubuntu.com-20080520093154-qalsy1z1slax40z0
Tags: 1.5.4-1
* New upstream version.
* Updated my email address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
84
84
                if (foundat[2] == '\x03' && foundat[3] == '\x04')       //Verfiy we are looking at a local file header//
85
85
                        {
86
86
                        
87
 
                        localFH.compression=htos(&foundat[8], LITTLE_ENDIAN);
88
 
                        localFH.compressed = htoi(&foundat[18], LITTLE_ENDIAN);
89
 
                        localFH.uncompressed = htoi(&foundat[22], LITTLE_ENDIAN);
90
 
                        localFH.filename_length = htos(&foundat[26], LITTLE_ENDIAN);
91
 
                        localFH.extra_length = htos(&foundat[28], LITTLE_ENDIAN);;
92
 
                        localFH.genFlag = htos(&foundat[6], LITTLE_ENDIAN);     
 
87
                        localFH.compression=htos(&foundat[8], FOREMOST_LITTLE_ENDIAN);
 
88
                        localFH.compressed = htoi(&foundat[18], FOREMOST_LITTLE_ENDIAN);
 
89
                        localFH.uncompressed = htoi(&foundat[22], FOREMOST_LITTLE_ENDIAN);
 
90
                        localFH.filename_length = htos(&foundat[26], FOREMOST_LITTLE_ENDIAN);
 
91
                        localFH.extra_length = htos(&foundat[28], FOREMOST_LITTLE_ENDIAN);;
 
92
                        localFH.genFlag = htos(&foundat[6], FOREMOST_LITTLE_ENDIAN);    
93
93
 
94
94
                        // Sanity checking
95
95
                        if (localFH.compressed > needle->max_len)
217
217
                        return NULL;
218
218
                        }
219
219
 
220
 
                comment_length = htos(foundat, LITTLE_ENDIAN);
 
220
                comment_length = htos(foundat, FOREMOST_LITTLE_ENDIAN);
221
221
                foundat += comment_length + 2;
222
222
                file_size = (foundat - buf);
223
223
#ifdef DEBUG
236
236
#ifdef DEBUG
237
237
                printf("Found a %s\n", needle->suffix);
238
238
#endif
239
 
                return foundat;
 
239
                return foundat-2;
240
240
        }
241
241
 
242
242
        if (bytes_to_search > buflen - (currentpos - buf))
749
749
                }
750
750
 
751
751
        blknum = htoi((unsigned char *) &h->root_start_block, FOREMOST_LITTLE_ENDIAN);
 
752
 
 
753
        if(blknum < 0)
 
754
        {
 
755
                return buf + 10;
 
756
        }
 
757
 
752
758
        highblock = htoi((unsigned char *) &h->dir_flag, FOREMOST_LITTLE_ENDIAN);
753
759
#ifdef DEBUG
754
760
        printf("getting dir block\n");
760
766
#ifdef DEBUG
761
767
        printf("done getting dir block\n");
762
768
#endif
763
 
        validblk = (blknum + 1) * OUR_BLK_SIZE;
 
769
        validblk = (blknum + 1) * OUR_BLK_SIZE; 
764
770
        while (blknum != END_OF_CHAIN)
765
771
        {
766
772
#ifdef DEBUG
771
777
 
772
778
                /**PROBLEMA**/
773
779
#ifdef DEBUG
774
 
                printf("***blknum:=%d FATblk:=%d\n", blknum, FATblk);
 
780
                printf("***blknum:=%d FATblk:=%d ourblksize=%d\n", blknum, FATblk,OUR_BLK_SIZE);
775
781
#endif
776
782
                oldblk = blknum;
777
783
                htoi_c = (unsigned char *) &FAT[blknum / (OUR_BLK_SIZE / sizeof(int))];
1113
1119
        unsigned char   *header = foundat;
1114
1120
        unsigned char   *extractbuf = NULL;
1115
1121
        unsigned char   *buf = foundat;
1116
 
        u_int64_t               size = 0;
 
1122
        unsigned int            size = 0;
1117
1123
        u_int64_t               file_size = 0;
1118
 
        int                             headerSize = 0;
1119
 
        int                             fileObjHeaderSize = 0;
 
1124
        u_int64_t                       headerSize = 0;
 
1125
        u_int64_t                       fileObjHeaderSize = 0;
1120
1126
        int                             numberofHeaderObjects = 0;
1121
1127
        int                             reserved[2];
1122
1128
        int                             bytes_to_search = 0;
1127
1133
 
1128
1134
        foundat += 16;          /*Jump to the header size*/
1129
1135
        headerSize = htoll(foundat, FOREMOST_LITTLE_ENDIAN);
 
1136
        //printx(foundat,0,8);
1130
1137
        foundat += 8;
1131
1138
        numberofHeaderObjects = htoi(foundat, FOREMOST_LITTLE_ENDIAN);
1132
1139
        foundat += 4;           //Jump to the begin File properties obj
1133
1140
        reserved[0] = foundat[0];
1134
1141
        reserved[1] = foundat[1];
1135
1142
        foundat += 2;
1136
 
 
 
1143
        //printf("found WMV\n");
1137
1144
        //end header obj
1138
1145
        //****************************************************/
1139
1146
        //Sanity Check
 
1147
        //printf("WMV num_header_objs=%d headerSize=%llu\n",numberofHeaderObjects,headerSize);
 
1148
 
1140
1149
        if (headerSize <= 0 || numberofHeaderObjects <= 0 || reserved[0] != 1)
1141
1150
                {
 
1151
                printf("WMV err num_header_objs=%d headerSize=%llu\n",numberofHeaderObjects,headerSize);
1142
1152
                return foundat;
1143
1153
                }
1144
1154
 
1159
1169
        if (foundat)
1160
1170
                {
1161
1171
                foundat += 16;  /*jump to the headersize*/
1162
 
                fileObjHeaderSize = htoll(foundat, LITTLE_ENDIAN);
 
1172
                fileObjHeaderSize = htoll(foundat, FOREMOST_LITTLE_ENDIAN);
 
1173
                //printx(foundat,0,8);
1163
1174
                foundat += 24;  //Jump to the file size obj
1164
 
                size = htoi(foundat, LITTLE_ENDIAN);
 
1175
                size = htoi(foundat, FOREMOST_LITTLE_ENDIAN);
 
1176
                //printx(foundat,0,8);
 
1177
                
1165
1178
#ifdef DEBUG
1166
 
                printf("SIZE:=%lld\n", size);
 
1179
                printf("SIZE:=%u fileObjHeaderSize=%llu\n", size,fileObjHeaderSize);
1167
1180
#endif
1168
1181
                }
1169
1182
        else
1291
1304
                return buf + needle->header_len;
1292
1305
 
1293
1306
        /*JUMP the first to bytes of the header (BM)*/
1294
 
        size = htoi(&foundat[2], LITTLE_ENDIAN);        /*Grab the total file size in little_endian*/
 
1307
        size = htoi(&foundat[2], FOREMOST_LITTLE_ENDIAN);       /*Grab the total file size in little_endian*/
1295
1308
 
1296
1309
        /*Sanity Check*/
1297
1310
        if (size <= 100 || size > needle->max_len)
1336
1349
 
1337
1350
                file_size = size;
1338
1351
                extractbuf = buf;
1339
 
                write_to_disk(s, needle, file_size, extractbuf, c_offset + f_offset);
 
1352
                
 
1353
                write_to_disk(s, needle, file_size, extractbuf, (c_offset + f_offset)-4);
1340
1354
                foundat += file_size;
1341
1355
                return foundat;
1342
1356
 
1604
1618
 *Function: extract_png
1605
1619
 *Description: Given that we have a PNG header parse the given buffer to determine
1606
1620
 *      where the file ends.
1607
 
 *Return: A pointer to where the EOF of the JPEG is in the current buffer
 
1621
 *Return: A pointer to where the EOF of the PNG is in the current buffer
1608
1622
 **********************************************************************************/
1609
1623
unsigned char *extract_png(f_state *s, u_int64_t c_offset, unsigned char *foundat, u_int64_t buflen,
1610
1624
                                                   s_spec *needle, u_int64_t f_offset)
1704
1718
        unsigned char   *currentpos = NULL;
1705
1719
 
1706
1720
        unsigned char   *extractbuf = NULL;
1707
 
        signed short    headersize = 0;
 
1721
        unsigned short  headersize = 0;
1708
1722
        int                             bytes_to_search = 0;
1709
1723
        int                             hasTable = FALSE;
1710
1724
        int                             hasHuffman = FALSE;
1743
1757
#ifdef DEBUG
1744
1758
                printf("Headersize:=%d buflen:=%lld\n", headersize, buflen);
1745
1759
#endif
1746
 
                if (headersize < 0)
1747
 
                {
1748
 
#ifdef DEBUG
1749
 
                        printf("Negative header size\n");
1750
 
#endif
1751
 
                        return buf + needle->header_len;;
1752
 
                }
1753
1760
 
1754
 
                if (headersize > buflen)
1755
 
                        {
1756
 
                        return NULL;
1757
 
                        }
 
1761
                
 
1762
                if (((foundat + headersize) - buf) > buflen){ return NULL; }    
1758
1763
 
1759
1764
                foundat += headersize;
1760
 
 
 
1765
                
1761
1766
                if (foundat[2] != (unsigned char)'\xff')
1762
1767
                        {
1763
1768
                        break;
1779
1784
                        }
1780
1785
        }
1781
1786
 
1782
 
        /*All jpegs must contact a Huffman marker as well as a quantization table*/
 
1787
        /*All jpegs must contain a Huffman marker as well as a quantization table*/
1783
1788
        if (!hasTable || !hasHuffman)
1784
1789
        {
1785
1790
#ifdef DEBUG