The Linux Page

Bad move for PHP unpack()! So unpack() stopped working?

Today I noticed many errors on one of my websites. Looking closer into it, I noticed that the code for the mo_references Drupal module stopped working.

It took me some time, especially because the code seemed to work just fine as all the files could easily be displayed.

Actually, that was not the case. The unpack() character 'a', which I used, was transformed from a simple string that gets trimmed, to all the characters, including the NULL characters. Ouch! Now we have to use the 'Z' character instead.

I use it to unpack() a tar file by loading 512 bytes of data in a variable and then extracting the different fields with the unpack() command as in:

[...]
$block = gzread($gz, 512)
$header = unpack("Z100name/Z8mode/Z8uid/Z8gid/Z12size/Z12mtime/"
               . "Z8checksum/Z1type/Z100symlink/Z6magic/Z2temp/"
               . "Z32temp/Z32temp/Z8temp/Z8temp/Z155prefix/Z12temp", $block);
if($header['magic'] == 'ustar')
{
   // looks valid, go on
}

Source: http://www.php.net/manual/en/function.unpack.php

Syndicate content

SMS From Me Logo

SMS From Me

To automatically start one on one conversations with your online leads.

     

   

Terms of Site Index

Find the page/content you are looking for with our index.

  • Made to Order Software

    Made to Order Software is my company. m2osw for short. We offer many different types of software including some for Drupal (the CMS used for this very site.)

  • Qt

    Qt is a multi-platform development system for servers, command line tools, and graphical applications (GUI). It allows you to create objects that will work on many operating systems with very minimal if any changes.

  • Solaris
  • label
  • run