php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79736 ZipArchive accepts backslashes for file names
Submitted: 2020-06-25 18:45 UTC Modified: 2020-07-07 08:18 UTC
From: edultra at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Zip Related
PHP Version: 7.2.31 OS: Windows and Linux
Private report: No CVE-ID: None
 [2020-06-25 18:45 UTC] edultra at gmail dot com
Description:
------------
Quando você utiliza o ziparchive para criar um zip de uma pasta com subpastas e arquivos em um servidor windows ele cria o arquivo, porém na descompressão em um servidor Linux os arquivos ficam todos errados, pelo que consegui descobrir é devido a posição da barra que ele faz para o windows exemplo:

a pasta no windows contém a seguinte estrutura/arquivos:

index.html
images
    image1.jpg
    image2.jpg
    image3.jpg
styles
    style.css
content
    home.html
    capitulo.html
    footer.html

Pelo que vi ele salva o caminho para despois descomprimir
index.html
images\image1.jpg
images\image2.jpg
images\image3.jpg
styles\style.css
content\home.html
content\capitulo.html
content\footer.html

Vejam que a posição no windows da barra é \ porém nesta posição o php interpreta que é para desconsiderar o próximo caracter ficando assim os caminhos no linux:
index.html
images\mage1.jpg
images\mage2.jpg
images\mage3.jpg
styles\tyle.css
content\ome.html
content\apitulo.html
content\ooter.html

Os arquivos na raiz são extrai dos com sucesso mas os outros geram arquivos todos errados.

Expected result:
----------------
Que os arquivos sejam extrai dos corretamente tanto os gerados no windows e extraidos no linux e vice-versa.

Actual result:
--------------
Os arquivos são extraidos todos com problema.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-06-25 18:49 UTC] peehaa@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: peehaa
 [2020-06-25 18:49 UTC] peehaa@php.net
Non English.

If you think this is a valid bug report feel free to submit it again in English.
 [2020-06-25 18:52 UTC] requinix@php.net
-Status: Closed +Status: Re-Opened -Assigned To: peehaa +Assigned To:
 [2020-06-25 18:52 UTC] requinix@php.net
When you use ziparchive to zip a folder with
subfolders and files on a windows server it creates the file, however
decompression on a Linux server the files are all wrong,
from what I was able to discover is due to the position of the bar that it does
for windows example:

the folder on windows contains the following structure / files:

index.html
images
image1.jpg
image2.jpg
image3.jpg
styles
style.css
content
home.html
chapter.html
footer.html

From what I saw he saves the way to decompress
index.html
images \ image1.jpg
images \ image2.jpg
images \ image3.jpg
styles \ style.css
content \ home.html
content \ chapter.html
content \ footer.html

See that the position in the windows of the bar is \ however in this position the
php interprets that it is to disregard the next character getting
so the paths in linux:
index.html
images \ mage1.jpg
images \ mage2.jpg
images \ mage3.jpg
styles \ tyle.css
content \ ome.html
content \ apitulo.html
content \ ooter.html

The root files are successfully extracted but the others generate
all wrong files.

Expected result:
----------------
That the files are extracted correctly both those generated in the
windows and extracted in linux and vice versa.

Actual result:
--------------
The files are extracted all with problem.
 [2020-06-30 14:58 UTC] cmb@php.net
-Package: *Compression related +Package: Zip Related
 [2020-07-07 08:18 UTC] cmb@php.net
-Summary: ZipArchive +Summary: ZipArchive accepts backslashes for file names -Status: Re-Opened +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2020-07-07 08:18 UTC] cmb@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

ZipArchive is very liberal in what it accepts as filename (i.e.
$localname), and as such accepts backslashes.  The documentation
of ZipArchive::addFile()[1] (and other relevant methods) states:

| For maximum portability, it is recommended to always use forward
| slashes (/) as directory separator in ZIP filenames.

[1] <https://www.php.net/manual/en/ziparchive.addfile.php>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 19:01:33 2024 UTC