ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
getid3_zip Class Reference

getID3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g // More...

+ Inheritance diagram for getid3_zip:
+ Collaboration diagram for getid3_zip:

Public Member Functions

 Analyze ()
 
 getZIPHeaderFilepointerTopDown ()
 
 getZIPentriesFilepointer ()
 
 ZIPparseLocalFileHeader ()
 
 ZIPparseCentralDirectory ()
 
 ZIPparseEndOfCentralDirectory ()
 
- Public Member Functions inherited from getid3_handler
 __construct (getID3 $getid3, $call_module=null)
 
 Analyze ()
 
 AnalyzeString ($string)
 
 setStringMode ($string)
 
 saveAttachment ($name, $offset, $length, $image_mime=null)
 

Static Public Member Functions

static ZIPparseGeneralPurposeFlags ($flagbytes, $compressionmethod)
 
static ZIPversionOSLookup ($index)
 
static ZIPcompressionMethodLookup ($index)
 
static DOStime2UNIXtime ($DOSdate, $DOStime)
 

Additional Inherited Members

- Protected Member Functions inherited from getid3_handler
 ftell ()
 
 fread ($bytes)
 
 fseek ($bytes, $whence=SEEK_SET)
 
 feof ()
 
 isDependencyFor ($module)
 
 error ($text)
 
 warning ($text)
 
 notice ($text)
 
- Protected Attributes inherited from getid3_handler
 $getid3
 
 $data_string_flag = false
 
 $data_string = ''
 
 $data_string_position = 0
 
 $data_string_length = 0
 

Detailed Description

getID3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //

Definition at line 18 of file module.archive.zip.php.

Member Function Documentation

◆ Analyze()

getid3_zip::Analyze ( )

Definition at line 21 of file module.archive.zip.php.

References $info, $key, array, getid3_lib\array_merge_clobber(), getid3_lib\CreateDeepArray(), getid3_handler\error(), getid3_handler\fread(), getid3_handler\fseek(), getZIPentriesFilepointer(), getid3_lib\intValueSupported(), getid3_handler\warning(), ZIPparseCentralDirectory(), ZIPparseEndOfCentralDirectory(), and ZIPparseLocalFileHeader().

21  {
22  $info = &$this->getid3->info;
23 
24  $info['fileformat'] = 'zip';
25  $info['zip']['encoding'] = 'ISO-8859-1';
26  $info['zip']['files'] = array();
27 
28  $info['zip']['compressed_size'] = 0;
29  $info['zip']['uncompressed_size'] = 0;
30  $info['zip']['entries_count'] = 0;
31 
32  if (!getid3_lib::intValueSupported($info['filesize'])) {
33  $this->error('File is larger than '.round(PHP_INT_MAX / 1073741824).'GB, not supported by PHP');
34  return false;
35  } else {
36  $EOCDsearchData = '';
37  $EOCDsearchCounter = 0;
38  while ($EOCDsearchCounter++ < 512) {
39 
40  $this->fseek(-128 * $EOCDsearchCounter, SEEK_END);
41  $EOCDsearchData = $this->fread(128).$EOCDsearchData;
42 
43  if (strstr($EOCDsearchData, 'PK'."\x05\x06")) {
44 
45  $EOCDposition = strpos($EOCDsearchData, 'PK'."\x05\x06");
46  $this->fseek((-128 * $EOCDsearchCounter) + $EOCDposition, SEEK_END);
47  $info['zip']['end_central_directory'] = $this->ZIPparseEndOfCentralDirectory();
48 
49  $this->fseek($info['zip']['end_central_directory']['directory_offset']);
50  $info['zip']['entries_count'] = 0;
51  while ($centraldirectoryentry = $this->ZIPparseCentralDirectory($this->getid3->fp)) {
52  $info['zip']['central_directory'][] = $centraldirectoryentry;
53  $info['zip']['entries_count']++;
54  $info['zip']['compressed_size'] += $centraldirectoryentry['compressed_size'];
55  $info['zip']['uncompressed_size'] += $centraldirectoryentry['uncompressed_size'];
56 
57  //if ($centraldirectoryentry['uncompressed_size'] > 0) { zero-byte files are valid
58  if (!empty($centraldirectoryentry['filename'])) {
59  $info['zip']['files'] = getid3_lib::array_merge_clobber($info['zip']['files'], getid3_lib::CreateDeepArray($centraldirectoryentry['filename'], '/', $centraldirectoryentry['uncompressed_size']));
60  }
61  }
62 
63  if ($info['zip']['entries_count'] == 0) {
64  $this->error('No Central Directory entries found (truncated file?)');
65  return false;
66  }
67 
68  if (!empty($info['zip']['end_central_directory']['comment'])) {
69  $info['zip']['comments']['comment'][] = $info['zip']['end_central_directory']['comment'];
70  }
71 
72  if (isset($info['zip']['central_directory'][0]['compression_method'])) {
73  $info['zip']['compression_method'] = $info['zip']['central_directory'][0]['compression_method'];
74  }
75  if (isset($info['zip']['central_directory'][0]['flags']['compression_speed'])) {
76  $info['zip']['compression_speed'] = $info['zip']['central_directory'][0]['flags']['compression_speed'];
77  }
78  if (isset($info['zip']['compression_method']) && ($info['zip']['compression_method'] == 'store') && !isset($info['zip']['compression_speed'])) {
79  $info['zip']['compression_speed'] = 'store';
80  }
81 
82  // secondary check - we (should) already have all the info we NEED from the Central Directory above, but scanning each
83  // Local File Header entry will
84  foreach ($info['zip']['central_directory'] as $central_directory_entry) {
85  $this->fseek($central_directory_entry['entry_offset']);
86  if ($fileentry = $this->ZIPparseLocalFileHeader()) {
87  $info['zip']['entries'][] = $fileentry;
88  } else {
89  $this->warning('Error parsing Local File Header at offset '.$central_directory_entry['entry_offset']);
90  }
91  }
92 
93  if (!empty($info['zip']['files']['[Content_Types].xml']) &&
94  !empty($info['zip']['files']['_rels']['.rels']) &&
95  !empty($info['zip']['files']['docProps']['app.xml']) &&
96  !empty($info['zip']['files']['docProps']['core.xml'])) {
97  // http://technet.microsoft.com/en-us/library/cc179224.aspx
98  $info['fileformat'] = 'zip.msoffice';
99  if (!empty($ThisFileInfo['zip']['files']['ppt'])) {
100  $info['mime_type'] = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
101  } elseif (!empty($ThisFileInfo['zip']['files']['xl'])) {
102  $info['mime_type'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
103  } elseif (!empty($ThisFileInfo['zip']['files']['word'])) {
104  $info['mime_type'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
105  }
106  }
107 
108  return true;
109  }
110  }
111  }
112 
113  if (!$this->getZIPentriesFilepointer()) {
114  unset($info['zip']);
115  $info['fileformat'] = '';
116  $this->error('Cannot find End Of Central Directory (truncated file?)');
117  return false;
118  }
119 
120  // central directory couldn't be found and/or parsed
121  // scan through actual file data entries, recover as much as possible from probable trucated file
122  if ($info['zip']['compressed_size'] > ($info['filesize'] - 46 - 22)) {
123  $this->error('Warning: Truncated file! - Total compressed file sizes ('.$info['zip']['compressed_size'].' bytes) is greater than filesize minus Central Directory and End Of Central Directory structures ('.($info['filesize'] - 46 - 22).' bytes)');
124  }
125  $this->error('Cannot find End Of Central Directory - returned list of files in [zip][entries] array may not be complete');
126  foreach ($info['zip']['entries'] as $key => $valuearray) {
127  $info['zip']['files'][$valuearray['filename']] = $valuearray['uncompressed_size'];
128  }
129  return true;
130  }
error($text)
Definition: getid3.php:1752
static intValueSupported($num)
Definition: getid3.lib.php:80
warning($text)
Definition: getid3.php:1758
fread($bytes)
Definition: getid3.php:1683
Create styles array
The data for the language used.
static array_merge_clobber($array1, $array2)
Definition: getid3.lib.php:384
fseek($bytes, $whence=SEEK_SET)
Definition: getid3.php:1711
$info
Definition: index.php:5
$key
Definition: croninfo.php:18
static CreateDeepArray($ArrayPath, $Separator, $Value)
Definition: getid3.lib.php:491
+ Here is the call graph for this function:

◆ DOStime2UNIXtime()

static getid3_zip::DOStime2UNIXtime (   $DOSdate,
  $DOStime 
)
static

Definition at line 487 of file module.archive.zip.php.

Referenced by ZIPparseCentralDirectory(), and ZIPparseLocalFileHeader().

487  {
488  // wFatDate
489  // Specifies the MS-DOS date. The date is a packed 16-bit value with the following format:
490  // Bits Contents
491  // 0-4 Day of the month (1-31)
492  // 5-8 Month (1 = January, 2 = February, and so on)
493  // 9-15 Year offset from 1980 (add 1980 to get actual year)
494 
495  $UNIXday = ($DOSdate & 0x001F);
496  $UNIXmonth = (($DOSdate & 0x01E0) >> 5);
497  $UNIXyear = (($DOSdate & 0xFE00) >> 9) + 1980;
498 
499  // wFatTime
500  // Specifies the MS-DOS time. The time is a packed 16-bit value with the following format:
501  // Bits Contents
502  // 0-4 Second divided by 2
503  // 5-10 Minute (0-59)
504  // 11-15 Hour (0-23 on a 24-hour clock)
505 
506  $UNIXsecond = ($DOStime & 0x001F) * 2;
507  $UNIXminute = (($DOStime & 0x07E0) >> 5);
508  $UNIXhour = (($DOStime & 0xF800) >> 11);
509 
510  return gmmktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear);
511  }
+ Here is the caller graph for this function:

◆ getZIPentriesFilepointer()

getid3_zip::getZIPentriesFilepointer ( )

Definition at line 179 of file module.archive.zip.php.

References $info, getid3_handler\error(), and ZIPparseLocalFileHeader().

Referenced by Analyze().

179  {
180  $info = &$this->getid3->info;
181 
182  $info['zip']['compressed_size'] = 0;
183  $info['zip']['uncompressed_size'] = 0;
184  $info['zip']['entries_count'] = 0;
185 
186  rewind($this->getid3->fp);
187  while ($fileentry = $this->ZIPparseLocalFileHeader()) {
188  $info['zip']['entries'][] = $fileentry;
189  $info['zip']['entries_count']++;
190  $info['zip']['compressed_size'] += $fileentry['compressed_size'];
191  $info['zip']['uncompressed_size'] += $fileentry['uncompressed_size'];
192  }
193  if ($info['zip']['entries_count'] == 0) {
194  $this->error('No Local File Header entries found');
195  return false;
196  }
197 
198  return true;
199  }
error($text)
Definition: getid3.php:1752
$info
Definition: index.php:5
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getZIPHeaderFilepointerTopDown()

getid3_zip::getZIPHeaderFilepointerTopDown ( )

Definition at line 133 of file module.archive.zip.php.

References $info, getid3_handler\error(), ZIPparseCentralDirectory(), ZIPparseEndOfCentralDirectory(), and ZIPparseLocalFileHeader().

133  {
134  $info = &$this->getid3->info;
135 
136  $info['fileformat'] = 'zip';
137 
138  $info['zip']['compressed_size'] = 0;
139  $info['zip']['uncompressed_size'] = 0;
140  $info['zip']['entries_count'] = 0;
141 
142  rewind($this->getid3->fp);
143  while ($fileentry = $this->ZIPparseLocalFileHeader()) {
144  $info['zip']['entries'][] = $fileentry;
145  $info['zip']['entries_count']++;
146  }
147  if ($info['zip']['entries_count'] == 0) {
148  $this->error('No Local File Header entries found');
149  return false;
150  }
151 
152  $info['zip']['entries_count'] = 0;
153  while ($centraldirectoryentry = $this->ZIPparseCentralDirectory($this->getid3->fp)) {
154  $info['zip']['central_directory'][] = $centraldirectoryentry;
155  $info['zip']['entries_count']++;
156  $info['zip']['compressed_size'] += $centraldirectoryentry['compressed_size'];
157  $info['zip']['uncompressed_size'] += $centraldirectoryentry['uncompressed_size'];
158  }
159  if ($info['zip']['entries_count'] == 0) {
160  $this->error('No Central Directory entries found (truncated file?)');
161  return false;
162  }
163 
164  if ($EOCD = $this->ZIPparseEndOfCentralDirectory()) {
165  $info['zip']['end_central_directory'] = $EOCD;
166  } else {
167  $this->error('No End Of Central Directory entry found (truncated file?)');
168  return false;
169  }
170 
171  if (!empty($info['zip']['end_central_directory']['comment'])) {
172  $info['zip']['comments']['comment'][] = $info['zip']['end_central_directory']['comment'];
173  }
174 
175  return true;
176  }
error($text)
Definition: getid3.php:1752
$info
Definition: index.php:5
+ Here is the call graph for this function:

◆ ZIPcompressionMethodLookup()

static getid3_zip::ZIPcompressionMethodLookup (   $index)
static

Definition at line 456 of file module.archive.zip.php.

References $index, and array.

Referenced by ZIPparseCentralDirectory(), and ZIPparseLocalFileHeader().

456  {
457  // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/ZIP.html
458  static $ZIPcompressionMethodLookup = array(
459  0 => 'store',
460  1 => 'shrink',
461  2 => 'reduce-1',
462  3 => 'reduce-2',
463  4 => 'reduce-3',
464  5 => 'reduce-4',
465  6 => 'implode',
466  7 => 'tokenize',
467  8 => 'deflate',
468  9 => 'deflate64',
469  10 => 'Imploded (old IBM TERSE)',
470  11 => 'RESERVED[11]',
471  12 => 'BZIP2',
472  13 => 'RESERVED[13]',
473  14 => 'LZMA (EFS)',
474  15 => 'RESERVED[15]',
475  16 => 'RESERVED[16]',
476  17 => 'RESERVED[17]',
477  18 => 'IBM TERSE (new)',
478  19 => 'IBM LZ77 z Architecture (PFS)',
479  96 => 'JPEG recompressed',
480  97 => 'WavPack compressed',
481  98 => 'PPMd version I, Rev 1',
482  );
483 
484  return (isset($ZIPcompressionMethodLookup[$index]) ? $ZIPcompressionMethodLookup[$index] : '[unknown]');
485  }
$index
Definition: metadata.php:60
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ ZIPparseCentralDirectory()

getid3_zip::ZIPparseCentralDirectory ( )

Definition at line 298 of file module.archive.zip.php.

References DOStime2UNIXtime(), getid3_handler\fread(), getid3_handler\fseek(), getid3_handler\ftell(), getid3_lib\LittleEndian2Int(), ZIPcompressionMethodLookup(), ZIPparseGeneralPurposeFlags(), and ZIPversionOSLookup().

Referenced by Analyze(), and getZIPHeaderFilepointerTopDown().

298  {
299  $CentralDirectory['offset'] = $this->ftell();
300 
301  $ZIPcentralDirectory = $this->fread(46);
302 
303  $CentralDirectory['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 0, 4));
304  if ($CentralDirectory['raw']['signature'] != 0x02014B50) {
305  // invalid Central Directory Signature
306  $this->fseek($CentralDirectory['offset']); // seek back to where filepointer originally was so it can be handled properly
307  return false;
308  }
309  $CentralDirectory['raw']['create_version'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 4, 2));
310  $CentralDirectory['raw']['extract_version'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 6, 2));
311  $CentralDirectory['raw']['general_flags'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 8, 2));
312  $CentralDirectory['raw']['compression_method'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 10, 2));
313  $CentralDirectory['raw']['last_mod_file_time'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 12, 2));
314  $CentralDirectory['raw']['last_mod_file_date'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 14, 2));
315  $CentralDirectory['raw']['crc_32'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 16, 4));
316  $CentralDirectory['raw']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 20, 4));
317  $CentralDirectory['raw']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 24, 4));
318  $CentralDirectory['raw']['filename_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 28, 2));
319  $CentralDirectory['raw']['extra_field_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 30, 2));
320  $CentralDirectory['raw']['file_comment_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 32, 2));
321  $CentralDirectory['raw']['disk_number_start'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 34, 2));
322  $CentralDirectory['raw']['internal_file_attrib'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 36, 2));
323  $CentralDirectory['raw']['external_file_attrib'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 38, 4));
324  $CentralDirectory['raw']['local_header_offset'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 42, 4));
325 
326  $CentralDirectory['entry_offset'] = $CentralDirectory['raw']['local_header_offset'];
327  $CentralDirectory['create_version'] = sprintf('%1.1f', $CentralDirectory['raw']['create_version'] / 10);
328  $CentralDirectory['extract_version'] = sprintf('%1.1f', $CentralDirectory['raw']['extract_version'] / 10);
329  $CentralDirectory['host_os'] = $this->ZIPversionOSLookup(($CentralDirectory['raw']['extract_version'] & 0xFF00) >> 8);
330  $CentralDirectory['compression_method'] = $this->ZIPcompressionMethodLookup($CentralDirectory['raw']['compression_method']);
331  $CentralDirectory['compressed_size'] = $CentralDirectory['raw']['compressed_size'];
332  $CentralDirectory['uncompressed_size'] = $CentralDirectory['raw']['uncompressed_size'];
333  $CentralDirectory['flags'] = $this->ZIPparseGeneralPurposeFlags($CentralDirectory['raw']['general_flags'], $CentralDirectory['raw']['compression_method']);
334  $CentralDirectory['last_modified_timestamp'] = $this->DOStime2UNIXtime($CentralDirectory['raw']['last_mod_file_date'], $CentralDirectory['raw']['last_mod_file_time']);
335 
336  $FilenameExtrafieldCommentLength = $CentralDirectory['raw']['filename_length'] + $CentralDirectory['raw']['extra_field_length'] + $CentralDirectory['raw']['file_comment_length'];
337  if ($FilenameExtrafieldCommentLength > 0) {
338  $FilenameExtrafieldComment = $this->fread($FilenameExtrafieldCommentLength);
339 
340  if ($CentralDirectory['raw']['filename_length'] > 0) {
341  $CentralDirectory['filename'] = substr($FilenameExtrafieldComment, 0, $CentralDirectory['raw']['filename_length']);
342  }
343  if ($CentralDirectory['raw']['extra_field_length'] > 0) {
344  $CentralDirectory['raw']['extra_field_data'] = substr($FilenameExtrafieldComment, $CentralDirectory['raw']['filename_length'], $CentralDirectory['raw']['extra_field_length']);
345  }
346  if ($CentralDirectory['raw']['file_comment_length'] > 0) {
347  $CentralDirectory['file_comment'] = substr($FilenameExtrafieldComment, $CentralDirectory['raw']['filename_length'] + $CentralDirectory['raw']['extra_field_length'], $CentralDirectory['raw']['file_comment_length']);
348  }
349  }
350 
351  return $CentralDirectory;
352  }
static ZIPcompressionMethodLookup($index)
static LittleEndian2Int($byteword, $signed=false)
Definition: getid3.lib.php:292
static ZIPversionOSLookup($index)
fread($bytes)
Definition: getid3.php:1683
static ZIPparseGeneralPurposeFlags($flagbytes, $compressionmethod)
fseek($bytes, $whence=SEEK_SET)
Definition: getid3.php:1711
static DOStime2UNIXtime($DOSdate, $DOStime)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ZIPparseEndOfCentralDirectory()

getid3_zip::ZIPparseEndOfCentralDirectory ( )

Definition at line 354 of file module.archive.zip.php.

References getid3_handler\fread(), getid3_handler\fseek(), getid3_handler\ftell(), and getid3_lib\LittleEndian2Int().

Referenced by Analyze(), and getZIPHeaderFilepointerTopDown().

354  {
355  $EndOfCentralDirectory['offset'] = $this->ftell();
356 
357  $ZIPendOfCentralDirectory = $this->fread(22);
358 
359  $EndOfCentralDirectory['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 0, 4));
360  if ($EndOfCentralDirectory['signature'] != 0x06054B50) {
361  // invalid End Of Central Directory Signature
362  $this->fseek($EndOfCentralDirectory['offset']); // seek back to where filepointer originally was so it can be handled properly
363  return false;
364  }
365  $EndOfCentralDirectory['disk_number_current'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 4, 2));
366  $EndOfCentralDirectory['disk_number_start_directory'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 6, 2));
367  $EndOfCentralDirectory['directory_entries_this_disk'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 8, 2));
368  $EndOfCentralDirectory['directory_entries_total'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 10, 2));
369  $EndOfCentralDirectory['directory_size'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 12, 4));
370  $EndOfCentralDirectory['directory_offset'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 16, 4));
371  $EndOfCentralDirectory['comment_length'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 20, 2));
372 
373  if ($EndOfCentralDirectory['comment_length'] > 0) {
374  $EndOfCentralDirectory['comment'] = $this->fread($EndOfCentralDirectory['comment_length']);
375  }
376 
377  return $EndOfCentralDirectory;
378  }
static LittleEndian2Int($byteword, $signed=false)
Definition: getid3.lib.php:292
fread($bytes)
Definition: getid3.php:1683
fseek($bytes, $whence=SEEK_SET)
Definition: getid3.php:1711
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ZIPparseGeneralPurposeFlags()

static getid3_zip::ZIPparseGeneralPurposeFlags (   $flagbytes,
  $compressionmethod 
)
static

Definition at line 381 of file module.archive.zip.php.

Referenced by ZIPparseCentralDirectory(), and ZIPparseLocalFileHeader().

381  {
382  // https://users.cs.jmu.edu/buchhofp/forensics/formats/pkzip-printable.html
383  $ParsedFlags['encrypted'] = (bool) ($flagbytes & 0x0001);
384  // 0x0002 -- see below
385  // 0x0004 -- see below
386  $ParsedFlags['data_descriptor_used'] = (bool) ($flagbytes & 0x0008);
387  $ParsedFlags['enhanced_deflation'] = (bool) ($flagbytes & 0x0010);
388  $ParsedFlags['compressed_patched_data'] = (bool) ($flagbytes & 0x0020);
389  $ParsedFlags['strong_encryption'] = (bool) ($flagbytes & 0x0040);
390  // 0x0080 - unused
391  // 0x0100 - unused
392  // 0x0200 - unused
393  // 0x0400 - unused
394  $ParsedFlags['language_encoding'] = (bool) ($flagbytes & 0x0800);
395  // 0x1000 - reserved
396  $ParsedFlags['mask_header_values'] = (bool) ($flagbytes & 0x2000);
397  // 0x4000 - reserved
398  // 0x8000 - reserved
399 
400  switch ($compressionmethod) {
401  case 6:
402  $ParsedFlags['dictionary_size'] = (($flagbytes & 0x0002) ? 8192 : 4096);
403  $ParsedFlags['shannon_fano_trees'] = (($flagbytes & 0x0004) ? 3 : 2);
404  break;
405 
406  case 8:
407  case 9:
408  switch (($flagbytes & 0x0006) >> 1) {
409  case 0:
410  $ParsedFlags['compression_speed'] = 'normal';
411  break;
412  case 1:
413  $ParsedFlags['compression_speed'] = 'maximum';
414  break;
415  case 2:
416  $ParsedFlags['compression_speed'] = 'fast';
417  break;
418  case 3:
419  $ParsedFlags['compression_speed'] = 'superfast';
420  break;
421  }
422  break;
423  }
424 
425  return $ParsedFlags;
426  }
+ Here is the caller graph for this function:

◆ ZIPparseLocalFileHeader()

getid3_zip::ZIPparseLocalFileHeader ( )

Definition at line 202 of file module.archive.zip.php.

References DOStime2UNIXtime(), getid3_handler\fread(), getid3_handler\fseek(), getid3_handler\ftell(), getid3_lib\LittleEndian2Int(), getid3_lib\PrintHexBytes(), getid3_handler\warning(), ZIPcompressionMethodLookup(), ZIPparseGeneralPurposeFlags(), and ZIPversionOSLookup().

Referenced by Analyze(), getZIPentriesFilepointer(), and getZIPHeaderFilepointerTopDown().

202  {
203  $LocalFileHeader['offset'] = $this->ftell();
204 
205  $ZIPlocalFileHeader = $this->fread(30);
206 
207  $LocalFileHeader['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 0, 4));
208  if ($LocalFileHeader['raw']['signature'] != 0x04034B50) { // "PK\x03\x04"
209  // invalid Local File Header Signature
210  $this->fseek($LocalFileHeader['offset']); // seek back to where filepointer originally was so it can be handled properly
211  return false;
212  }
213  $LocalFileHeader['raw']['extract_version'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 4, 2));
214  $LocalFileHeader['raw']['general_flags'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 6, 2));
215  $LocalFileHeader['raw']['compression_method'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 8, 2));
216  $LocalFileHeader['raw']['last_mod_file_time'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 10, 2));
217  $LocalFileHeader['raw']['last_mod_file_date'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 12, 2));
218  $LocalFileHeader['raw']['crc_32'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 14, 4));
219  $LocalFileHeader['raw']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 18, 4));
220  $LocalFileHeader['raw']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 22, 4));
221  $LocalFileHeader['raw']['filename_length'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 26, 2));
222  $LocalFileHeader['raw']['extra_field_length'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 28, 2));
223 
224  $LocalFileHeader['extract_version'] = sprintf('%1.1f', $LocalFileHeader['raw']['extract_version'] / 10);
225  $LocalFileHeader['host_os'] = $this->ZIPversionOSLookup(($LocalFileHeader['raw']['extract_version'] & 0xFF00) >> 8);
226  $LocalFileHeader['compression_method'] = $this->ZIPcompressionMethodLookup($LocalFileHeader['raw']['compression_method']);
227  $LocalFileHeader['compressed_size'] = $LocalFileHeader['raw']['compressed_size'];
228  $LocalFileHeader['uncompressed_size'] = $LocalFileHeader['raw']['uncompressed_size'];
229  $LocalFileHeader['flags'] = $this->ZIPparseGeneralPurposeFlags($LocalFileHeader['raw']['general_flags'], $LocalFileHeader['raw']['compression_method']);
230  $LocalFileHeader['last_modified_timestamp'] = $this->DOStime2UNIXtime($LocalFileHeader['raw']['last_mod_file_date'], $LocalFileHeader['raw']['last_mod_file_time']);
231 
232  $FilenameExtrafieldLength = $LocalFileHeader['raw']['filename_length'] + $LocalFileHeader['raw']['extra_field_length'];
233  if ($FilenameExtrafieldLength > 0) {
234  $ZIPlocalFileHeader .= $this->fread($FilenameExtrafieldLength);
235 
236  if ($LocalFileHeader['raw']['filename_length'] > 0) {
237  $LocalFileHeader['filename'] = substr($ZIPlocalFileHeader, 30, $LocalFileHeader['raw']['filename_length']);
238  }
239  if ($LocalFileHeader['raw']['extra_field_length'] > 0) {
240  $LocalFileHeader['raw']['extra_field_data'] = substr($ZIPlocalFileHeader, 30 + $LocalFileHeader['raw']['filename_length'], $LocalFileHeader['raw']['extra_field_length']);
241  }
242  }
243 
244  if ($LocalFileHeader['compressed_size'] == 0) {
245  // *Could* be a zero-byte file
246  // But could also be a file written on the fly that didn't know compressed filesize beforehand.
247  // Correct compressed filesize should be in the data_descriptor located after this file data, and also in Central Directory (at end of zip file)
248  if (!empty($this->getid3->info['zip']['central_directory'])) {
249  foreach ($this->getid3->info['zip']['central_directory'] as $central_directory_entry) {
250  if ($central_directory_entry['entry_offset'] == $LocalFileHeader['offset']) {
251  if ($central_directory_entry['compressed_size'] > 0) {
252  // overwrite local zero value (but not ['raw']'compressed_size']) so that seeking for data_descriptor (and next file entry) works correctly
253  $LocalFileHeader['compressed_size'] = $central_directory_entry['compressed_size'];
254  }
255  break;
256  }
257  }
258  }
259 
260  }
261  $LocalFileHeader['data_offset'] = $this->ftell();
262  $this->fseek($LocalFileHeader['compressed_size'], SEEK_CUR); // this should (but may not) match value in $LocalFileHeader['raw']['compressed_size'] -- $LocalFileHeader['compressed_size'] could have been overwritten above with value from Central Directory
263 
264  if ($LocalFileHeader['flags']['data_descriptor_used']) {
265  $DataDescriptor = $this->fread(16);
266  $LocalFileHeader['data_descriptor']['signature'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 0, 4));
267  if ($LocalFileHeader['data_descriptor']['signature'] != 0x08074B50) { // "PK\x07\x08"
268  $this->getid3->warning[] = 'invalid Local File Header Data Descriptor Signature at offset '.($this->ftell() - 16).' - expecting 08 07 4B 50, found '.getid3_lib::PrintHexBytes($LocalFileHeader['data_descriptor']['signature']);
269  $this->fseek($LocalFileHeader['offset']); // seek back to where filepointer originally was so it can be handled properly
270  return false;
271  }
272  $LocalFileHeader['data_descriptor']['crc_32'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 4, 4));
273  $LocalFileHeader['data_descriptor']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 8, 4));
274  $LocalFileHeader['data_descriptor']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 12, 4));
275  if (!$LocalFileHeader['raw']['compressed_size'] && $LocalFileHeader['data_descriptor']['compressed_size']) {
276  foreach ($this->getid3->info['zip']['central_directory'] as $central_directory_entry) {
277  if ($central_directory_entry['entry_offset'] == $LocalFileHeader['offset']) {
278  if ($LocalFileHeader['data_descriptor']['compressed_size'] == $central_directory_entry['compressed_size']) {
279  // $LocalFileHeader['compressed_size'] already set from Central Directory
280  } else {
281  $this->warning('conflicting compressed_size from data_descriptor ('.$LocalFileHeader['data_descriptor']['compressed_size'].') vs Central Directory ('.$central_directory_entry['compressed_size'].') for file at offset '.$LocalFileHeader['offset']);
282  }
283 
284  if ($LocalFileHeader['data_descriptor']['uncompressed_size'] == $central_directory_entry['uncompressed_size']) {
285  $LocalFileHeader['uncompressed_size'] = $LocalFileHeader['data_descriptor']['uncompressed_size'];
286  } else {
287  $this->warning('conflicting uncompressed_size from data_descriptor ('.$LocalFileHeader['data_descriptor']['uncompressed_size'].') vs Central Directory ('.$central_directory_entry['uncompressed_size'].') for file at offset '.$LocalFileHeader['offset']);
288  }
289  break;
290  }
291  }
292  }
293  }
294  return $LocalFileHeader;
295  }
static ZIPcompressionMethodLookup($index)
warning($text)
Definition: getid3.php:1758
static LittleEndian2Int($byteword, $signed=false)
Definition: getid3.lib.php:292
static ZIPversionOSLookup($index)
static PrintHexBytes($string, $hex=true, $spaces=true, $htmlencoding='UTF-8')
Definition: getid3.lib.php:18
fread($bytes)
Definition: getid3.php:1683
static ZIPparseGeneralPurposeFlags($flagbytes, $compressionmethod)
fseek($bytes, $whence=SEEK_SET)
Definition: getid3.php:1711
static DOStime2UNIXtime($DOSdate, $DOStime)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ZIPversionOSLookup()

static getid3_zip::ZIPversionOSLookup (   $index)
static

Definition at line 429 of file module.archive.zip.php.

References $index, and array.

Referenced by ZIPparseCentralDirectory(), and ZIPparseLocalFileHeader().

429  {
430  static $ZIPversionOSLookup = array(
431  0 => 'MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems)',
432  1 => 'Amiga',
433  2 => 'OpenVMS',
434  3 => 'Unix',
435  4 => 'VM/CMS',
436  5 => 'Atari ST',
437  6 => 'OS/2 H.P.F.S.',
438  7 => 'Macintosh',
439  8 => 'Z-System',
440  9 => 'CP/M',
441  10 => 'Windows NTFS',
442  11 => 'MVS',
443  12 => 'VSE',
444  13 => 'Acorn Risc',
445  14 => 'VFAT',
446  15 => 'Alternate MVS',
447  16 => 'BeOS',
448  17 => 'Tandem',
449  18 => 'OS/400',
450  19 => 'OS/X (Darwin)',
451  );
452 
453  return (isset($ZIPversionOSLookup[$index]) ? $ZIPversionOSLookup[$index] : '[unknown]');
454  }
$index
Definition: metadata.php:60
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: