Mantis - Quercus
Viewing Issue Advanced Details
3894 block always 02-18-10 07:36 06-22-12 00:04
domdorn  
nam  
high  
closed 4.0.11  
unable to reproduce  
none    
none  
0003894: Maximum String length of 8KB breaks phorum.org forum software
the file in each current phorum.org installation
phorum5/include/templates.php
contains a method:

[code]
function phorum_read_file($file)
{
    // Check if the file exists.
    if (! file_exists($file)) trigger_error(
        "phorum_get_file_contents: file \"" . htmlspecialchars($file) . "\" " .
        "does not exist",
        E_USER_ERROR
    );

    // In case we're handling a zero byte large file, we don't read it in.
    // Running fread($fp, 0) gives a PHP warning.
    $size = filesize($file);
    if ($size == 0) return "";


// $data = readfile($file);
// return $data;
    // Read in the file contents.
    if (! $fp = fopen($file, "r")) trigger_error(
        "phorum_get_file_contents: failed to read file " .
        "\"" . htmlspecialchars($file) . "\"",
        E_USER_ERROR
    );
    // Strip UTF-8 byte order markers from the files. These only mean
    // harm for PHP scripts.
    $data = '';
    if ($size >= 3) {
        $data = fread($fp, 3);
        if ($data == "\xef\xbb\xbf") {
            $data = '';
        }
        $size -= 3;
    }
    // Read the rest of the file.
    if ($size > 0) {
        $data .= fread($fp, $size);
    }
    fclose($fp);

// code inserted by me start
    $realFileSize = filesize($file);
    $readFileSize = 0;
    mail("removed@host.com",
    "readfile: $file",
    "realFileSize: $realFileSize \n Size of read file: $readFileSize\n\n",
    "From: mymail@myhost.com");
// code inserted by me end
    return $data;
}
[/code]

supplied with an example file which I'll attach here, quercus only reads exactly 8192 Bytes of that file and deletes the rest which leads to errors.
I'm running current trunk in revision 6775 on Glassfish v3.

The received mail states:
realFileSize: 9537
 Size of read file: 8192

 0i82.qa [^] (817 bytes) 09-28-10 07:50

Notes
(0004433)
domdorn   
02-18-10 07:38   
File tpl-lyriks.at-posting-4c86722b2ad3c8bae6c585d3ae2fb850.php-stage2 gets created by phorum in the end result. As the original template got truncated after 8kb, the resulting PHP code is invalid.
(0004434)
domdorn   
02-18-10 08:52   
Ok, I created a testcase for this, modified the code like that:
function phorum_read_file($file, $quercus_max_read_size_at_one_time)
{
    // Check if the file exists.
    if (! file_exists($file)) trigger_error(
        "phorum_get_file_contents: file \"" . htmlspecialchars($file) . "\" " .
        "does not exist",
        E_USER_ERROR
    );

    // In case we're handling a zero byte large file, we don't read it in.
    // Running fread($fp, 0) gives a PHP warning.
    $size = filesize($file);
    if ($size == 0) return "";


// $data = readfile($file);
// return $data;
    // Read in the file contents.
    if (! $fp = fopen($file, "r")) trigger_error(
        "phorum_get_file_contents: failed to read file " .
        "\"" . htmlspecialchars($file) . "\"",
        E_USER_ERROR
    );
    // Strip UTF-8 byte order markers from the files. These only mean
    // harm for PHP scripts.
    $data = '';
    if ($size >= 3) {
        $data = fread($fp, 3);
        if ($data == "\xef\xbb\xbf") {
            $data = '';
        }
        $size -= 3;
    }
    ;
    // Read the rest of the file.
    while($size > 0)
    {
        $remainingSize = $size > $quercus_max_read_size_at_one_time ? $quercus_max_read_size_at_one_time : $size;
        $data .= fread($fp, $remainingSize);
        $size -= $remainingSize;
    }
// if ($size > 0 ) {
//
// $data .= fread($fp, $size);
// }
    fclose($fp);

    return $data;
}

quercus returns the correct result only if $quercus_max_read_size_at_one_time is set to 8189, while php returns the correct result with every number > 0

I've created the output for quercus and with native php and put it all runnable into the attached tar.gz file. Please fix asap. I can patch the forum code for now, but I don't know where this issue is still hidden in other php software and no one has the time and knowledge to manually fix it.
(0004678)
dunand   
07-20-10 10:51   
This Behavior make Wordpress 3.0 in French unusable because Wordpress is unable to load the translation file fr_FR.mo. The fread funtion read only 8164 bytes but the file is much larger.

Quercus 4.0.8
with Tomcat 5.5 or WebSphere 6.1.0.31
(0004760)
domdorn   
09-28-10 06:58   
working on this now.
(0004761)
domdorn   
09-28-10 07:51   
added QA file for demonstrating the issue.
(0004762)
domdorn   
09-28-10 09:51   
fixed in current SVN Rev. r7556.

Should be in 4.0.11 release.

(0004777)
domdorn   
10-05-10 14:16   
this introduced a regression with sockets. reopening.
(0005933)
nam   
06-22-12 00:04   
Looks fixed as indicated by php/0i82 test case.