[wp-trac] Re: [WordPress Trac] #5599: Sporadic timeout /wp-includes/gettext.php

WordPress Trac wp-trac at lists.automattic.com
Sun Jun 22 13:46:55 GMT 2008


#5599: Sporadic timeout /wp-includes/gettext.php
--------------------------------------+-------------------------------------
 Reporter:  WhitewolfFox              |        Owner:  westi   
     Type:  defect                    |       Status:  assigned
 Priority:  highest omg bbq           |    Milestone:  2.6     
Component:  General                   |      Version:  2.3.2   
 Severity:  critical                  |   Resolution:          
 Keywords:  gettext unpack() timeout  |  
--------------------------------------+-------------------------------------
Changes (by codestyling):

  * severity:  normal => critical

Comment:

 The problem has been detected and is very strange: The PHP function
 substr() returns sometimes a string, that has an additional offset of 1
 byte!
 I have traced this at an affected system, where this randomly occures and
 wrote an extra logfile and detection code. Here comes the issue:

 {{{
 de_DE.mo (Filestart, hex):
 DE 12 04 95 00 00 00 00 5E 08 00 00 1C 00 00 00

 int: -1794895138     -> hex: FFFFFFFF950412DE  (byte order mark, ok)
 int: 1577058304      -> hex: 5E000000 (revision, failed! 1 byte additional
 offset)
 int: 469762056       -> hex: 1C000008 (string count, failed!)
 int: 201326592       -> hex: 0C000000 (offset original table, failed!)
 int: 687865923       -> hex:29000043 (offset translation table, failed!)
 }}}

 This leads to this bad behavoir, because all integers are wrong and too
 big for file size.

 I have written a fix inside '''streams.php''' and did replace substr()
 call to unpack() call and now it works at the tested machine as expected
 without any further occurances.

 streams.php  line: 84

 old code:

 {{{
   function read($bytes) {
     $data = substr($this->_str, $this->_pos, $bytes);
     $this->_pos += $bytes;
     if (strlen($this->_str)<$this->_pos)
       $this->_pos = strlen($this->_str);

     return $data;
   }
 }}}

 new code:

 {{{
   function read($bytes) {
     $data = array_shift(unpack('@'.$this->_pos.'/A'.$bytes, $this->_str));
     $this->_pos += $bytes;
     if (strlen($this->_str)<$this->_pos)
       $this->_pos = strlen($this->_str);

     return $data;
   }
 }}}

 I think, this should be also reported to PHP core team for further
 investigation.
 I have tested this patch successful using de_DE.mo / ar.mo (arabic for rtl
 purpose) and ja.mo (japanees for extra unicode space).

-- 
Ticket URL: <http://trac.wordpress.org/ticket/5599#comment:14>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list