Skip to content

ZipArchive::getFromIndex() ignores ZipArchive::FL_UNCHANGED for deleted entries #21705

@LamentXU123

Description

@LamentXU123

Description

The following code:

<?php
$name = __DIR__ . '/test.zip';
@unlink($name);
$zip = new ZipArchive;
$zip->open($name, ZipArchive::CREATE);
$zip->addFromString('foo.txt', 'foo');
$zip->addFromString('bar.txt', 'bar');
$zip->close();

$zip = new ZipArchive;
$zip->open($name);

$index = $zip->locateName('bar.txt');
$zip->deleteName('bar.txt');

var_dump($zip->getFromName('bar.txt', 0, ZipArchive::FL_UNCHANGED));
var_dump($zip->getFromIndex($index, 0, ZipArchive::FL_UNCHANGED)); // the ZipArchive::FL_UNCHANGED is ignored

$zip->close();
@unlink($name);
?>

Resulted in this output:

string(3) "bar"
bool(false)

But I expected this output instead:

string(3) "bar"
string(3) "bar"

Seems like ZipArchive::getFromIndex() accepts a $flags argument, but in ext/zip/php_zip.c the index lookup path does not pass those flags to zip_stat_index(). getFromName() works, but getFromIndex() does not honor FL_UNCHANGED.

PHP Version

all supported version

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions