/** * Generates test fixtures from RAR sample files. * * @param boolean $pretend debug output only? * @param boolean $refresh regenerate existing files? * @return void */ function makeRarFixtures($pretend = false, $refresh = true) { $rar = new RarInfo(); foreach (glob(dirname(__FILE__) . '/rar/*.rar') as $rarfile) { $fname = pathinfo($rarfile, PATHINFO_BASENAME) . '.blocks'; $file = dirname(__FILE__) . "/rar/{$fname}"; if (!$refresh && file_exists($file)) { continue; } echo "Generating for {$rarfile}:\n"; $rar->open($rarfile, true); if ($rar->error) { echo "Error: {$rar->error}\n"; continue; } $data = $rar->getBlocks(); if (!$pretend) { $data = "<?php\nreturn " . var_export($data, true) . ";\n"; file_put_contents($file, $data); } echo "-- {$fname}\n"; } }
/** * Fixes issue #9, memory exhaustion on bad RAR50 file * * @depends testBasicRar50Support */ public function testRar50BadExtraSize() { $rar = new RarInfo(); $rar->open($this->fixturesDir . '/rar50_bad_extra_size.rar'); $this->assertSame(RarInfo::FMT_RAR50, $rar->format); $this->assertEmpty($rar->error); // The third file entry is corrupt, so isn't displayed in file list $this->assertSame(3, $rar->fileCount); $files = $rar->getFileList(); $this->assertCount(2, $files); // Bad block, header size points beyond file end $blocks = $rar->getBlocks(); $this->assertSame(5, count($blocks)); $this->assertSame('File', $blocks[4]['type']); $this->assertSame(11, $blocks[4]['extra_size']); $this->assertEmpty($blocks[4]['file_name']); // Comments in summary $summary = $rar->getSummary(); $this->assertArrayHasKey('comments', $summary); $this->assertStringStartsWith('German:', $summary['comments']); }