php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #77523 extend glob pattern limit of 2048 characters
Submitted: 2019-01-25 23:24 UTC Modified: 2021-08-04 16:34 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: nospam at unclassified dot de Assigned: cmb (profile)
Status: Wont fix Package: *Directory/Filesystem functions
PHP Version: 7.1.26 OS: Windows 10.1709
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nospam at unclassified dot de
New email:
PHP Version: OS:

 

 [2019-01-25 23:24 UTC] nospam at unclassified dot de
Description:
------------
This is what I do:

glob("pages/[Cc][Oo][Nn][Tt][Aa][Cc][Tt]/[Oo][Dd][Ll][Rr]0[Vv][Ss]8[Cc][Gg][Rr][Jj][Bb][Ii][Ll][Aa][Ww][Gg][Pp][Nn][Bb][Tt][Rr]4[Uu][Dd]3[Bb][Nn][Kk][Aa][Ee]/[Dd][Ee][Mm][Oo]/[Ii][Mm][Gg]/[Vv][Ss]2018[Jj][Aa][Vv][Aa][Ss][Cc][Rr][Ii][Pp][Tt][Ww][Aa][Rr][Nn][Ii][Nn][Gg][Ss].[Pp][Nn][Gg]")

This is what I get:

Warning: glob(): Pattern exceeds the maximum allowed length of 260 characters

The string passed to glob() is 279 characters long. And it may even be longer. I has to be this complicated to determine the correct casing of a file name on disk.

This restriction is neither documented nor understandable. The pattern length should not matter at all. And even if you think that file paths of actual files in the filesystem are limited to 260 characters on Windows, you may need to update your knowledge from at least 20 years ago. This restriction only exists for deprecated legacy software, which I hope PHP is not.

Test script:
---------------
See above.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-01-26 00:03 UTC] requinix@php.net
If you're on Windows then case doesn't matter, and even if it did this feels like an abuse of glob(). Tokenizing by slash and recursively scandir()ing makes more sense to me.

It's true that PHP's glob() limits the pattern to MAXPATHLEN characters when this doesn't quite make sense - with features like [] and {} the pattern can certainly be longer than the filenames it would match. So perhaps that check should be dropped.

Regardless, on my Win 10 PHP 7.1 the (PHP_)MAXPATHLEN is 2048 and your code runs fine. What SAPI (eg, php-fpm, cli) are you running this from, and did you get PHP from windows.php.net or somewhere else?
 [2019-01-26 09:30 UTC] nospam at unclassified dot de
I need a safe and reliable way to determine the true casing of a file name. On Linux it's easy, spell it as it is or you won't find it. Windows is more tolerant, accepting anything you throw at it. But that also means that my pages are accessible through a number of different URLs. I need my pages to be accessible on exactly one URL, so I'm correcting the spelling to the true file name. On Linux, this also allows me to accept different casing but redirect the user to the correct name.

I'm running XAMPP with Apache and PHP on Windows. It uses mod_php. I haven't tested this on Linux yet, that would be an Ubuntu 16.04 system with its default PHP packages and FastCGI.
 [2019-06-14 08:41 UTC] sjon@php.net
-Summary: glob pattern is limited to 260 characters +Summary: extend glob pattern limit of 260 characters -Type: Bug +Type: Feature/Change Request
 [2019-06-14 09:11 UTC] cmb@php.net
-Summary: extend glob pattern limit of 260 characters +Summary: extend glob pattern limit of 2048 characters
 [2019-06-14 09:11 UTC] cmb@php.net
Like @requinix already stated, the maximum allowed pattern length
is 2048 as of PHP 7.1.  I do not see the need to extend this.
 [2021-08-04 16:34 UTC] cmb@php.net
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2021-08-04 16:34 UTC] cmb@php.net
> I do not see the need to extend this.

I still don't see that.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 06:01:30 2024 UTC