php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49531 CURLOPT_INFILESIZE sometimes causes warning "CURLPROTO_FILE cannot be set"
Submitted: 2009-09-11 12:40 UTC Modified: 2009-09-23 02:08 UTC
Votes:4
Avg. Score:4.8 ± 0.4
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:0 (0.0%)
From: gilad at parann dot net Assigned: felipe (profile)
Status: Closed Package: cURL related
PHP Version: 5.2, 5.3 and HEAD OS: any (was seen on Win32 XP)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: gilad at parann dot net
New email:
PHP Version: OS:

 

 [2009-09-11 12:40 UTC] gilad at parann dot net
Description:
------------
Set up PHP 5.2.10 with a basedir.

Calling 

curl_setopt ($ch, CURLOPT_INFILESIZE, $len) ;

will sometimes cause PHP to generate a warning

CURLPROTO_FILE cannot be activated when in safe_mode or an open_basedir is set

depending on the exact value of $len !!!

Looking at the source code of _php_curl_setopt (from "...ext/curl/interface.c") I think I see why. The code starts with a big switch statement and NO break...

So the CURLOPT_INFILESIZE option gets processed by the IF statement that checks if "(Z_LVAL_PP(zvalue) & CURLPROTO_FILE)" !!

Sometimes the $len value will happen to have the same bits set as  CURLPROTO_FILE and boom - you get the error.

Anyway if you avoid setting INFILESIZE things do work - only sometimes that is not so convenient...

Reproduce code:
---------------
from _php_curl_setopt in "...ext/curl/interface.c":

 switch (option) {
 	case CURLOPT_INFILESIZE: 
        /* ....  many many more options with NO break! */
        case CURLOPT_REDIR_PROTOCOLS:
 	case CURLOPT_PROTOCOLS:
 	convert_to_long_ex(zvalue);
			if (((PG(open_basedir) && *PG(open_basedir)) || PG(safe_mode)) && (Z_LVAL_PP(zvalue) & CURLPROTO_FILE)) {
					php_error_docref(NULL TSRMLS_CC, E_WARNING, "CURLPROTO_FILE cannot be activated when in safe_mode or an open_basedir is set");
					RETVAL_FALSE;
					return 1;
			}
			error = curl_easy_setopt(ch->cp, option, Z_LVAL_PP(zvalue));
			break;


Expected result:
----------------
I expect the call to curl_setopt with CURLOPT_INFILESIZE to work

Actual result:
--------------
A warning is generated

CURLPROTO_FILE cannot be activated when in safe_mode or an open_basedir is set


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-12 17:01 UTC] gilad at parann dot net
Further detail:

This was with PHP 5.2.10 and libcurl 7.19.4 in Apache 2.2.11 on Win32 (XP)
 [2009-09-17 07:41 UTC] bonecollector at hot dot ee
Seems, that other options cause also this warning:

<?
$chk_time=date('2009-08-07 10:10:10');

$resURL = curl_init();
curl_setopt($resURL, CURLOPT_URL, 'http://google.com');
curl_setopt($resURL, CURLOPT_TIMECONDITION,
CURL_TIMECOND_IFMODSINCE);
curl_setopt($resURL, CURLOPT_TIMEVALUE, $chk_time);
curl_setopt($resURL, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($resURL, CURLOPT_HEADER, TRUE);
$pageData=curl_exec($resURL);

echo "Got result:<br>";
echo $pageData;
?>

and you will get same warning on line 7 (curl_setopt($resURL,
CURLOPT_TIMEVALUE, $chk_time);)

Searching at google, it seems that many-many pages have been broken
 [2009-09-23 02:08 UTC] svn@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&revision=288598
Log: - Fixed bug #49531 (CURLOPT_INFILESIZE sometimes causes warning "CURLPROTO_FILE cannot be set ...")
 [2009-09-23 02:08 UTC] felipe@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Fixed in 5.2, 5.3 and HEAD. Thanks for reporting!
 [2009-10-10 09:17 UTC] svn@php.net
Automatic comment from SVN on behalf of pajoye
Revision: http://svn.php.net/viewvc/?view=revision&revision=289494
Log: - Merge: Fixed bug #49531 (CURLOPT_INFILESIZE sometimes causes warning ?\226?\128?\156CURLPROTO_FILE cannot be set ?\226?\128?\166)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Apr 01 03:01:29 2025 UTC