Skip to content
Permalink
Browse files

add patch to add length checks around the unpack(..., substr(....)) c…

…alls so it

  doesn't toss errors due to the string being too short fo the substr() calls

git-svn-id: https://svn.macports.org/repository/macports/trunk/dports@40497 d073be05-634f-4543-b044-5fe20cf6d1d6
  • Loading branch information
ghosthound committed Oct 3, 2008
1 parent 0053be9 commit 4c9d05e0c4052f7607c3455ac031a37bd42942b5
@@ -3,7 +3,7 @@
PortSystem 1.0
PortGroup perl5 1.0
perl5.setup Mac-AppleSingleDouble 1.0
revision 0
revision 1
maintainers ricci
description Read Mac files in AppleSingle or AppleDouble format
long_description \
@@ -15,3 +15,6 @@ platforms darwin
checksums md5 96343f4314905602f96e379baa25996f


patchfiles patch-lib-Mac-AppleSingleDouble.pm.diff


@@ -0,0 +1,113 @@
--- lib/Mac/AppleSingleDouble.pm.orig 2001-09-29 16:06:42.000000000 -0700
+++ lib/Mac/AppleSingleDouble.pm 2008-10-03 13:35:35.000000000 -0700
@@ -345,45 +345,71 @@

sub _parse_finder_info
{
- my $this = shift;
- my $finderinfo_raw = shift;
- my(%finderinfo);
-
- # based on page 7-76 of Inside Macintosh: Finder Interface
- $finderinfo{'Type'} = substr($finderinfo_raw, 0, 4);
- $finderinfo{'Creator'} = substr($finderinfo_raw, 4, 4);
- $finderinfo{'Flags'} = unpack('n', substr($finderinfo_raw, 8, 2));
- $finderinfo{'Location'} = unpack('nn', substr($finderinfo_raw, 10, 4));
- $finderinfo{'Fldr'} = unpack('n', substr($finderinfo_raw, 14, 2));
-
- # Finder Flags
- $flagbits = unpack('B8', substr($finderinfo_raw, 8, 1)) .unpack('B8', substr($finderinfo_raw, 9, 1)) ;
- #print "flagbits is $flagbits\n";
- $finderinfo{'Label'} = unpack('C', pack('B8', '0'x5 . substr($flagbits, 12, 3)));
- $finderinfo{'Color'} = $finderinfo{'Label'};
- $finderinfo{'IsOnDesk'} = substr($flagbits, 15, 1);
- $finderinfo{'IsShared'} = substr($flagbits, 9, 1);
- $finderinfo{'HasBeenInited'} = substr($flagbits, 7, 1);
- $finderinfo{'HasCustomIcon'} = substr($flagbits, 5, 1);
- $finderinfo{'IsStationery'} = substr($flagbits, 4, 1);
- $finderinfo{'NameLocked'} = substr($flagbits, 3, 1);
- $finderinfo{'HasBundle'} = substr($flagbits, 2, 1);
- $finderinfo{'IsInvisible'} = substr($flagbits, 1, 1);
- $finderinfo{'IsAlias'} = substr($flagbits, 0, 1);
-
- # Extended Finder Info
- $finderinfo{'IconID'} = unpack('n', substr($finderinfo_raw, 16, 2));
- $finderinfo{'Script'} = unpack('c', substr($finderinfo_raw, 24, 1));
- $finderinfo{'XFlags'} = unpack('B8', substr($finderinfo_raw, 25, 1));
- $finderinfo{'Comment'} = unpack('n', substr($finderinfo_raw, 26, 2));
- $finderinfo{'PutAway'} = unpack('N', substr($finderinfo_raw, 28, 4));
-
- my $labelcolor = $this->{'_labelcolors'}->{$finderinfo{'Label'}};
- my $labelname = $this->{'_labelnames'}->{$finderinfo{'Label'}};
- $finderinfo{'LabelColor'} = defined($labelcolor)? $labelcolor : '(no labelcolor provided)';
- $finderinfo{'LabelName'} = defined($labelname)? $labelname : '(no labelname provided)';
-
- $this->{'_finder_info'} = \%finderinfo;
+ my $this = shift;
+ my $finderinfo_raw = shift;
+ my(%finderinfo);
+ my $finderInfoRawLen = undef;
+
+ if (!defined($finderinfo_raw) || "" eq $finderinfo_raw) {
+ $this->{'_finder_info'} = \%finderinfo;
+ return;
+ }
+ $finderInfoRawLen = length $finderinfo_raw;
+
+ # based on page 7-76 of Inside Macintosh: Finder Interface
+ $finderinfo{'Type'} = substr($finderinfo_raw, 0, 4);
+ if ($finderInfoRawLen >= 4) {
+ $finderinfo{'Creator'} = substr($finderinfo_raw, 4, 4);
+ }
+ if ($finderInfoRawLen >= 8) {
+ $finderinfo{'Flags'} = unpack('n', substr($finderinfo_raw, 8, 2));
+ }
+ if ($finderInfoRawLen >= 9) {
+ # Finder Flags
+ $flagbits = unpack('B8', substr($finderinfo_raw, 8, 1)) .unpack('B8', substr($finderinfo_raw, 9, 1)) ;
+ #print "flagbits is $flagbits\n";
+ $finderinfo{'Label'} = unpack('C', pack('B8', '0'x5 . substr($flagbits, 12, 3)));
+ $finderinfo{'Color'} = $finderinfo{'Label'};
+ $finderinfo{'IsOnDesk'} = substr($flagbits, 15, 1);
+ $finderinfo{'IsShared'} = substr($flagbits, 9, 1);
+ $finderinfo{'HasBeenInited'} = substr($flagbits, 7, 1);
+ $finderinfo{'HasCustomIcon'} = substr($flagbits, 5, 1);
+ $finderinfo{'IsStationery'} = substr($flagbits, 4, 1);
+ $finderinfo{'NameLocked'} = substr($flagbits, 3, 1);
+ $finderinfo{'HasBundle'} = substr($flagbits, 2, 1);
+ $finderinfo{'IsInvisible'} = substr($flagbits, 1, 1);
+ $finderinfo{'IsAlias'} = substr($flagbits, 0, 1);
+ }
+ if ($finderInfoRawLen >= 10) {
+ $finderinfo{'Location'} = unpack('nn', substr($finderinfo_raw, 10, 4));
+ }
+ if ($finderInfoRawLen >= 14) {
+ $finderinfo{'Fldr'} = unpack('n', substr($finderinfo_raw, 14, 2));
+ }
+
+ # Extended Finder Info
+ if ($finderInfoRawLen >= 16) {
+ $finderinfo{'IconID'} = unpack('n', substr($finderinfo_raw, 16, 2));
+ }
+ if ($finderInfoRawLen >= 24) {
+ $finderinfo{'Script'} = unpack('c', substr($finderinfo_raw, 24, 1));
+ }
+ if ($finderInfoRawLen >= 25) {
+ $finderinfo{'XFlags'} = unpack('B8', substr($finderinfo_raw, 25, 1));
+ }
+ if ($finderInfoRawLen >= 26) {
+ $finderinfo{'Comment'} = unpack('n', substr($finderinfo_raw, 26, 2));
+ }
+ if ($finderInfoRawLen >= 28) {
+ $finderinfo{'PutAway'} = unpack('N', substr($finderinfo_raw, 28, 4));
+ }
+
+ my $labelcolor = $this->{'_labelcolors'}->{$finderinfo{'Label'}};
+ my $labelname = $this->{'_labelnames'}->{$finderinfo{'Label'}};
+ $finderinfo{'LabelColor'} = defined($labelcolor)? $labelcolor : '(no labelcolor provided)';
+ $finderinfo{'LabelName'} = defined($labelname)? $labelname : '(no labelname provided)';
+
+ $this->{'_finder_info'} = \%finderinfo;
}

sub _get_entry_from_file

0 comments on commit 4c9d05e

Please sign in to comment.
You can’t perform that action at this time.