php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #1830 Unpack() gives fatal error if not enough data.
Submitted: 1999-07-22 12:02 UTC Modified: 2002-01-27 01:18 UTC
From: danbeck at scott dot net Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0 OS: Linux 2.0.36 (RedHat 5.2)
Private report: No CVE-ID: None
 [1999-07-22 12:02 UTC] danbeck at scott dot net
Unpack dies with a fatal error if the length of the data does not match the length of the template supplied.

I know that this was intended, but it's sort of harsh, don't you think?  If you were relying on data from an external source, how would you handle bad data so that your scripts could continue working?  The only way I see here is to actually check the data to make sure it's the length of the template.  But this is error prone because if you ever changed  your template setup, you would need to update your minimum data size.

I think the perl way is *much* better.  If perl doesn't have enough data for the template, if fills out as many elements as it can and the rest of the array would be empty.  That way your script doesn't die in the middle of execution, it just doesn't return quite as much data as you expected.  

If I had a choice between displaying this to a user:

Fatal error: pack type A: not enough input, need 10, have 4 in /home/httpd/html/rpt/btrieve.phtml on line 496

or allowing me to check for missing elements in the array and responding appropriately, I prefer the latter.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-11-11 19:12 UTC] joey at cvs dot php dot net
While I agree that this is undesirable behavior,
I am moving this to a feature request, rather than
a misbehaving function, as the intended behavior
is correctly taking place.
 [2001-02-10 13:38 UTC] jimw@php.net
refiled against 4.0.
 [2002-01-27 01:18 UTC] sterling@php.net
Fixed in CVS, thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 11 00:01:31 2024 UTC