50 {
51 $info = &$this->getid3->info;
52
53 $info[
'fileformat'] =
'gzip';
54
55 $start_length = 10;
56 $unpack_header = 'a1id1/a1id2/a1cmethod/a1flags/a4mtime/a1xflags/a1os';
57
58
59
60
61 if (
$info[
'filesize'] >
$info[
'php_memory_limit']) {
62 $info[
'error'][] =
'File is too large (' . number_format(
$info[
'filesize']) .
' bytes) to read into memory (limit: ' . number_format(
$info[
'php_memory_limit'] / 1048576) .
'MB)';
63
64 return false;
65 }
66 fseek($this->getid3->fp, 0);
67 $buffer = fread($this->getid3->fp,
$info[
'filesize']);
68
69 $arr_members = explode("\x1F\x8B\x08", $buffer);
70 while (true) {
71 $is_wrong_members = false;
72 $num_members = intval(count($arr_members));
73 for ($i = 0; $i < $num_members; $i++) {
74 if (strlen($arr_members[$i]) == 0) {
75 continue;
76 }
77 $buf = "\x1F\x8B\x08" . $arr_members[$i];
78
79 $attr = unpack($unpack_header, substr($buf, 0, $start_length));
81
82 $arr_members[$i - 1] .= $buf;
83 $arr_members[$i] = '';
84 $is_wrong_members = true;
85 continue;
86 }
87 }
88 if (!$is_wrong_members) {
89 break;
90 }
91 }
92
93 $info[
'gzip'][
'files'] = array();
94
95 $fpointer = 0;
96 $idx = 0;
97 for ($i = 0; $i < $num_members; $i++) {
98 if (strlen($arr_members[$i]) == 0) {
99 continue;
100 }
101 $thisInfo = &
$info[
'gzip'][
'member_header'][++$idx];
102
103 $buff = "\x1F\x8B\x08" . $arr_members[$i];
104
105 $attr = unpack($unpack_header, substr($buff, 0, $start_length));
107 $thisInfo['raw']['id1'] = ord($attr['cmethod']);
108 $thisInfo['raw']['id2'] = ord($attr['cmethod']);
109 $thisInfo['raw']['cmethod'] = ord($attr['cmethod']);
110 $thisInfo['raw']['os'] = ord($attr['os']);
111 $thisInfo['raw']['xflags'] = ord($attr['xflags']);
112 $thisInfo['raw']['flags'] = ord($attr['flags']);
113
114 $thisInfo['flags']['crc16'] = (bool) ($thisInfo['raw']['flags'] & 0x02);
115 $thisInfo['flags']['extra'] = (bool) ($thisInfo['raw']['flags'] & 0x04);
116 $thisInfo['flags']['filename'] = (bool) ($thisInfo['raw']['flags'] & 0x08);
117 $thisInfo['flags']['comment'] = (bool) ($thisInfo['raw']['flags'] & 0x10);
118
119 $thisInfo[
'compression'] = $this->
get_xflag_type($thisInfo[
'raw'][
'xflags']);
120
121 $thisInfo[
'os'] = $this->
get_os_type($thisInfo[
'raw'][
'os']);
122 if (!$thisInfo['os']) {
123 $info[
'error'][] =
'Read error on gzip file';
124
125 return false;
126 }
127
128 $fpointer = 10;
129 $arr_xsubfield = array();
130
131
132
133
134 if ($thisInfo['flags']['extra']) {
135 $w_xlen = substr($buff, $fpointer, 2);
137 $fpointer += 2;
138
139 $thisInfo['raw']['xfield'] = substr($buff, $fpointer, $xlen);
140
141
142
143
144 $idx = 0;
145 while (true) {
146 if ($idx >= $xlen) {
147 break;
148 }
149 $si1 = ord(substr($buff, $fpointer + $idx++, 1));
150 $si2 = ord(substr($buff, $fpointer + $idx++, 1));
151 if (($si1 == 0x41) && ($si2 == 0x70)) {
152 $w_xsublen = substr($buff, $fpointer + $idx, 2);
154 $idx += 2;
155 $arr_xsubfield[] = substr($buff, $fpointer + $idx,
156 $xsublen);
157 $idx += $xsublen;
158 } else {
159 break;
160 }
161 }
162 $fpointer += $xlen;
163 }
164
165
166
167
168
169 $thisInfo['filename'] = preg_replace('#\.gz$#i', '',
171 if ($thisInfo['flags']['filename']) {
172 while (true) {
173 if (ord($buff[$fpointer]) == 0) {
174 $fpointer++;
175 break;
176 }
177 $thisInfo['filename'] .= $buff[$fpointer];
178 $fpointer++;
179 }
180 }
181
182
183
184
185 if ($thisInfo['flags']['comment']) {
186 while (true) {
187 if (ord($buff[$fpointer]) == 0) {
188 $fpointer++;
189 break;
190 }
191 $thisInfo['comment'] .= $buff[$fpointer];
192 $fpointer++;
193 }
194 }
195
196
197
198
199 if ($thisInfo['flags']['crc16']) {
200 $w_crc = substr($buff, $fpointer, 2);
202 $fpointer += 2;
203 }
204
205
206
207
208
209
211 strlen($buff) - 8,
212 4));
214 strlen($buff) - 4));
215
218 '/',
219 $thisInfo['filesize']));
220
221 if ($this->option_gzip_parse_contents) {
222
223 $csize = 0;
224 $inflated = '';
225 $chkcrc32 = '';
226 if (function_exists('gzinflate')) {
227 $cdata = substr($buff, $fpointer);
228 $cdata = substr($cdata, 0, strlen($cdata) - 8);
229 $csize = strlen($cdata);
230 $inflated = gzinflate($cdata);
231
232
233 $thisInfo[
'crc32_valid'] = (bool) (
sprintf(
'%u',
234 crc32($inflated)) == $thisInfo['crc32']);
235
236
237 $formattest = substr($inflated, 0, 32774);
238 $getid3_temp = new GetId3Core();
239 $determined_format = $getid3_temp->GetFileFormat($formattest);
240 unset($getid3_temp);
241
242
243 $determined_format['module'] = (isset($determined_format['module']) ? $determined_format['module'] : '');
244 switch ($determined_format['module']) {
245 case 'tar':
246
247 if (class_exists($determined_format['class'])) {
249 'getID3')) === false) {
250
251 $info[
'error'][] =
'Unable to create temp file to parse TAR inside GZIP file';
252 break;
253 }
254 if ($fp_temp_tar = fopen($temp_tar_filename,
255 'w+b')) {
256 fwrite($fp_temp_tar, $inflated);
257 fclose($fp_temp_tar);
258 $getid3_temp = new GetId3Core();
259 $getid3_temp->openfile($temp_tar_filename);
260 $getid3_tar = new Tar($getid3_temp);
261 $getid3_tar->analyze();
262 $info[
'gzip'][
'member_header'][$idx][
'tar'] = $getid3_temp->info[
'tar'];
263 unset($getid3_temp, $getid3_tar);
264 unlink($temp_tar_filename);
265 } else {
266 $info[
'error'][] =
'Unable to fopen() temp file to parse TAR inside GZIP file';
267 break;
268 }
269 }
270 break;
271
272 case '':
273 default:
274
275 break;
276 }
277 }
278 }
279 }
280
281 return true;
282 }
sprintf('%.4f', $callTime)
static array_merge_clobber($array1, $array2)
static LittleEndian2Int($byteword, $signed=false)
static CreateDeepArray($ArrayPath, $Separator, $Value)
get_xflag_type($key)
Converts the eXtra FLags.
get_os_type($key)
Converts the OS type.