Image/ExifTool/WriteQuickTime.pl

filter: Statementstmt 75.5% 1005 / 1330 Branchbran 57.0% 602 / 1056 Conditioncond 49.3% 345 / 699 MC/DCmcdc 24.1% 93 / 385 Subroutinesub 92.3% 12 / 13 Podpod 0.0% 0 / 12 totaltotal 58.8% 2057 / 3495 CC 787 SCAR 93.4
CC
787
Cov
63%
WriteQuickTime
16151.5
WriteItemInfo
1175.6
Handle_iloc
147.7
CRAP 11329.2
« Image/ExifTool/WriteExif.pl ↑ Summary Image/ExifTool/Exif.pm »
1 #------------------------------------------------------------------------------
2 # File: WriteQuickTime.pl
3 #
4 # Description: Write XMP to QuickTime (MOV and MP4) files
5 #
6 # Revisions: 2013-10-29 - P. Harvey Created
7 #------------------------------------------------------------------------------
8 package Image::ExifTool::QuickTime;
9  
10 23 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # maps for adding metadata to various QuickTime-based file types
13 23 my %movMap = (
14 # MOV (no 'ftyp', or 'ftyp'='qt ') -> XMP in 'moov'-'udta'-'XMP_'
15 QuickTime => 'ItemList', # (default location for QuickTime tags)
16 ItemList => 'Meta', # MOV-Movie-UserData-Meta-ItemList
17 Keys => 'Movie', # MOV-Movie-Meta-Keys !! (hack due to different Meta location)
18 AudioKeys => 'Track', # MOV-Movie-Track-Meta-Keys !!
19 VideoKeys => 'Track', # MOV-Movie-Track-Meta-Keys !!
20 Meta => 'UserData',
21 XMP => 'UserData', # MOV-Movie-UserData-XMP
22 Microsoft => 'UserData', # MOV-Movie-UserData-Microsoft
23 UserData => 'Movie', # MOV-Movie-UserData
24 Movie => 'MOV',
25 GSpherical => 'SphericalVideoXML', # MOV-Movie-Track-SphericalVideoXML
26 SphericalVideoXML => 'Track', # (video track specifically, don't create if it doesn't exist)
27 Track => 'Movie',
28 );
29 23 my %mp4Map = (
30 # MP4 ('ftyp' compatible brand 'mp41', 'mp42' or 'f4v ') -> XMP at top level
31 QuickTime => 'ItemList', # (default location for QuickTime tags)
32 ItemList => 'Meta', # MOV-Movie-UserData-Meta-ItemList
33 Keys => 'Movie', # MOV-Movie-Meta-Keys !! (hack due to different Meta location)
34 AudioKeys => 'Track', # MOV-Movie-Track-Meta-Keys !!
35 VideoKeys => 'Track', # MOV-Movie-Track-Meta-Keys !!
36 Meta => 'UserData',
37 UserData => 'Movie', # MOV-Movie-UserData
38 Microsoft => 'UserData', # MOV-Movie-UserData-Microsoft
39 Movie => 'MOV',
40 XMP => 'MOV', # MOV-XMP
41 GSpherical => 'SphericalVideoXML', # MOV-Movie-Track-SphericalVideoXML
42 SphericalVideoXML => 'Track', # (video track specifically, don't create if it doesn't exist)
43 Track => 'Movie',
44 );
45 23 my %heicMap = (
46 # HEIC/HEIF/AVIF ('ftyp' compatible brand 'heic','mif1','avif') -> XMP/EXIF in top level 'meta'
47 Meta => 'MOV',
48 ItemInformation => 'Meta',
49 ItemPropertyContainer => 'Meta',
50 XMP => 'ItemInformation',
51 EXIF => 'ItemInformation',
52 ICC_Profile => 'ItemPropertyContainer',
53 IFD0 => 'EXIF',
54 IFD1 => 'IFD0',
55 ExifIFD => 'IFD0',
56 GPS => 'IFD0',
57 SubIFD => 'IFD0',
58 GlobParamIFD => 'IFD0',
59 PrintIM => 'IFD0',
60 InteropIFD => 'ExifIFD',
61 MakerNotes => 'ExifIFD',
62 );
63 23 my %cr3Map = (
64 # CR3 ('ftyp' compatible brand 'crx ') -> XMP at top level
65 Movie => 'MOV',
66 XMP => 'MOV',
67 'UUID-Canon'=>'Movie',
68 ExifIFD => 'UUID-Canon',
69 IFD0 => 'UUID-Canon',
70 GPS => 'UUID-Canon',
71 #MakerNoteCanon => 'UUID-Canon', # (doesn't yet work -- goes into ExifIFD instead)
72 'UUID-Canon2' => 'MOV',
73 CanonVRD => 'UUID-Canon2',
74 );
75 23 my %dirMap = (
76 MOV => \%movMap,
77 MP4 => \%mp4Map,
78 CR3 => \%cr3Map,
79 HEIC => \%heicMap,
80 );
81  
82 # convert ExifTool Format to QuickTime type
83 23 my %qtFormat = (
84 'undef' => 0x00, string => 0x01,
85 int8s => 0x15, int16s => 0x15, int32s => 0x15, int64s => 0x15,
86 int8u => 0x16, int16u => 0x16, int32u => 0x16, int64u => 0x16,
87 float => 0x17, double => 0x18,
88 );
89 23 my $undLang = 0x55c4; # numeric code for default ('und') language
90  
91 23 my $maxReadLen = 100000000; # maximum size of atom to read into memory (100 MB)
92  
93 # boxes that may exist in an "empty" Meta box:
94 23 my %emptyMeta = (
95 hdlr => 'Handler', 'keys' => 'Keys', lang => 'Language', ctry => 'Country', free => 'Free',
96 );
97  
98 # starting word for Keys tags which use a full tag ID
99 23 my %fullKeysID = (
100 com => 1, xiaomi => 1, samsung => 1,
101 );
102  
103 # lookup for CTBO ID number based on uuid for Canon CR3 files
104 23 my %ctboID = (
105 "\xbe\x7a\xcf\xcb\x97\xa9\x42\xe8\x9c\x71\x99\x94\x91\xe3\xaf\xac" => 1, # XMP
106 "\xea\xf4\x2b\x5e\x1c\x98\x4b\x88\xb9\xfb\xb7\xdc\x40\x6e\x4d\x16" => 2, # PreviewImage
107 # ID 3 is used for 'mdat' atom (not a uuid)
108 # (haven't seen ID 4 yet)
109 "\x57\x66\xb8\x29\xbb\x6a\x47\xc5\xbc\xfb\x8b\x9f\x22\x60\xd0\x6d" => 5, # something to do with burst-roll image
110 );
111  
112 # mark UserData tags that don't have ItemList counterparts as Preferred
113 # - and set Preferred to 0 for any Avoid-ed tag
114 # - also, for now, set Writable to 0 for any tag with a RawConv and no RawConvInv
115 {
116 23 my $itemList = \%Image::ExifTool::QuickTime::ItemList;
117 23 my $userData = \%Image::ExifTool::QuickTime::UserData;
118 23 my (%pref, $tag);
119 23 foreach $tag (TagTableKeys($itemList)) {
120 2418 my $tagInfo = $$itemList{$tag};
121 2418 ▶ if (ref $tagInfo ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $tagInfo ne 'HASH') { } 448 1970 2418
122 448 ▶ next if ref $tagInfo;
Branch: 1 branch
BranchTrueFalseTotal
if ref $tagInfo 0 448 448
123 448 $tagInfo = $$itemList{$tag} = { Name => $tagInfo };
124 } else {
125 1970 ▶ $$tagInfo{Writable} = 0 if $$tagInfo{RawConv} and not $$tagInfo{RawConvInv};
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo->{"RawConv"} and not $tagInfo->{"RawConvInv"} 0 1970 1970
Condition33%1/3
$tagInfo->{"RawConv"} and not $tagInfo->{"RawConvInv"}
!ll&&!rl&&r
197000
MC/DC0%0/2
$tagInfo->{"RawConv"} and not $tagInfo->{"RawConvInv"}
$tagInfo->{"RawConv"} not $tagInfo->{"RawConvInv"}
Truth table33%1/3
A and not(B)
A= $tagInfo->{"RawConv"}B= not $tagInfo->{"RawConvInv"}
ABresult
0X0
100
111
126 1970 ▶ $$tagInfo{Avoid} and $$tagInfo{Preferred} = 0, next;
Branch: 1 branch
BranchTrueFalseTotal
$tagInfo->{"Avoid"} and $tagInfo->{"Preferred"} = 0, next 207 1763 1970
127 1763 ▶ next if defined $$tagInfo{Preferred} and not $$tagInfo{Preferred};
Branch: 1 branch
BranchTrueFalseTotal
if defined $tagInfo->{"Preferred"} and not $tagInfo->{"Preferred"} 0 1763 1763
Condition33%1/3
defined $tagInfo->{"Preferred"} and not $tagInfo->{"Preferred"}
!ll&&!rl&&r
176300
MC/DC0%0/2
defined $tagInfo->{"Preferred"} and not $tagInfo->{"Preferred"}
defined $tagInfo->{"Preferred"} not $tagInfo->{"Preferred"}
Truth table33%1/3
A and not(B)
A= defined $tagInfo->{"Preferred"}B= not $tagInfo->{"Preferred"}
ABresult
0X0
100
111
128 }
129 2211 $pref{$$tagInfo{Name}} = 1;
130 }
131 23 foreach $tag (TagTableKeys($userData)) {
132 4347 my $tagInfo = $$userData{$tag};
133 4347 ▶ if (ref $tagInfo ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $tagInfo ne 'HASH') { } 553 3794 4347
134 553 ▶ next if ref $tagInfo;
Branch: 1 branch
BranchTrueFalseTotal
if ref $tagInfo 115 438 553
135 438 $tagInfo = $$userData{$tag} = { Name => $tagInfo };
136 } else {
137 3794 ▶ $$tagInfo{Writable} = 0 if $$tagInfo{RawConv} and not $$tagInfo{RawConvInv};
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo->{"RawConv"} and not $tagInfo->{"RawConvInv"} 115 3679 3794
Condition100%3/3
$tagInfo->{"RawConv"} and not $tagInfo->{"RawConvInv"}
!ll&&!rl&&r
365623115
MC/DC100%2/2
$tagInfo->{"RawConv"} and not $tagInfo->{"RawConvInv"}
$tagInfo->{"RawConv"} not $tagInfo->{"RawConvInv"}
Truth table100%3/3
A and not(B)
A= $tagInfo->{"RawConv"}B= not $tagInfo->{"RawConvInv"}
ABresult
0X0
100
111
138 3794 ▶ $$tagInfo{Avoid} and $$tagInfo{Preferred} = 0, next;
Branch: 1 branch
BranchTrueFalseTotal
$tagInfo->{"Avoid"} and $tagInfo->{"Preferred"} = 0, next 667 3127 3794
139 3127 ▶ next if defined $$tagInfo{Preferred} or $pref{$$tagInfo{Name}};
Branch: 1 branch
BranchTrueFalseTotal
if defined $tagInfo->{"Preferred"} or $pref{$tagInfo->{"Name"}} 376 2751 3127
Condition66%2/3
defined $tagInfo->{"Preferred"} or $pref{$tagInfo->{"Name"}}
l!l&&r!l&&!r
03762751
MC/DC50%1/2
defined $tagInfo->{"Preferred"} or $pref{$tagInfo->{"Name"}}
defined $tagInfo->{"Preferred"} $pref{$tagInfo->{"Name"}}
Truth table66%2/3
A or B
A= defined $tagInfo->{"Preferred"}B= $pref{$tagInfo->{"Name"}}
ABresult
1X1
011
000
140 }
141 3189 $$tagInfo{Preferred} = 1;
142 }
143 }
144  
145 #------------------------------------------------------------------------------
146 # Format GPSCoordinates for writing
147 # Inputs: 0) PrintConv value
148 # Returns: ValueConv value
149 sub PrintInvGPSCoordinates($)
150 4 ▶{
Subroutine PrintInvGPSCoordinates: called CC=8 SCAR=29.4
Pod undocumented
151 4 my ($val, $et) = @_;
152 4 my @v = split /, */, $val;
153 4 ▶ if (@v == 2 or @v == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (@v == 2 or @v == 3) 4 0 4
Condition33%1/3
@v == 2 or @v == 3
l!l&&r!l&&!r
400
MC/DC0%0/2
@v == 2 or @v == 3
@v == 2 @v == 3
Truth table33%1/3
A or B
A= @v == 2B= @v == 3
ABresult
1X1
011
000
154 4 ▶ my $below = ($v[2] and $v[2] =~ /below/i);
Condition33%1/3
$v[2] && $v[2] =~ /below/i
!ll&&!rl&&r
400
MC/DC0%0/2
$v[2] && $v[2] =~ /below/i
$v[2] $v[2] =~ /below/i
Truth table33%1/3
A && B
A= $v[2]B= $v[2] =~ /below/i
ABresult
0X0
100
111
155 4 $v[0] = Image::ExifTool::GPS::ToDegrees($v[0], 1);
156 4 $v[1] = Image::ExifTool::GPS::ToDegrees($v[1], 1);
157 4 ▶ $v[2] = Image::ExifTool::ToFloat($v[2]) * ($below ? -1 : 1) if @v == 3;
Branch: 2 branches
BranchTrueFalseTotal
if @v == 3 0 4 4
$below ? : 0 0 0
158 4 return "@v";
159 }
160 0 ▶ return $val if $val =~ /^([-+]?\d+(\.\d*)?)\s+([-+]?\d+(\.\d*)?)$/; # already 2 floats?
Branch: 1 branch
BranchTrueFalseTotal
if $val =~ /^([-+]?\d+(\.\d*)?)\s+([-+]?\d+(\.\d*)?)$/ 0 0 0
161 0 ▶ return $val if $val =~ /^([-+]\d+(\.\d*)?){2,3}(CRS.*)?\/?$/; # already in ISO6709 format?
Branch: 1 branch
BranchTrueFalseTotal
if $val =~ m[^([-+]\d+(\.\d*)?){2,3}(CRS.*)?/?$] 0 0 0
162 0 return undef;
163 }
164  
165 #------------------------------------------------------------------------------
166 # Convert GPS coordinates back to ISO6709 format
167 # Inputs: 0) ValueConv value
168 # Returns: ISO6709 coordinates
169 sub ConvInvISO6709($)
170 40 ▶{
Subroutine ConvInvISO6709: called CC=11 SCAR=24.5
Pod undocumented
171 40 local $_;
172 40 my $val = shift;
173 40 my @a = split ' ', $val;
174 40 ▶ if (@a == 2 or @a == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a == 2 or @a == 3) 36 4 40
Condition100%3/3
@a == 2 or @a == 3
l!l&&r!l&&!r
16204
MC/DC100%2/2
@a == 2 or @a == 3
@a == 2 @a == 3
Truth table100%3/3
A or B
A= @a == 2B= @a == 3
ABresult
1X1
011
000
175 # latitude must have 2 digits before the decimal, and longitude 3,
176 # and all values must start with a "+" or "-", and Google Photos
177 # requires at least 3 digits after the decimal point
178 # (and as of Apr 2021, Google Photos doesn't accept coordinats
179 # with more than 5 digits after the decimal place:
180 # https://exiftool.org/forum/index.php?topic=11055.msg67171#msg67171
181 # still a problem Apr 2024: https://exiftool.org/forum/index.php?msg=85761)
182 36 my @fmt = ('%s%02d.%s%s','%s%03d.%s%s','%s%d.%s%s');
183 36 my @limit = (90,180);
184 36 foreach (@a) {
185 92 ▶ return undef unless Image::ExifTool::IsFloat($_);
Branch: 1 branch
BranchTrueFalseTotal
unless &Image::ExifTool::IsFloat($_) 0 92 92
186 92 my $lim = shift @limit;
187 92 ▶ warn((@limit ? 'Lat' : 'Long') . "itude out of range\n") if $lim and abs($_) > $lim;
Branch: 2 branches
BranchTrueFalseTotal
if $lim and abs $_ > $lim 0 92 92
@limit ? : 0 0 0
Condition66%2/3
$lim and abs $_ > $lim
!ll&&!rl&&r
20720
MC/DC0%0/2
$lim and abs $_ > $lim
$lim abs $_ > $lim
Truth table66%2/3
A and B
A= $limB= abs $_ > $lim
ABresult
0X0
100
111
188 92 ▶ $_ =~ s/^([-+]?)(\d+)\.?(\d*)/sprintf(shift(@fmt),$1||'+',$2,$3,length($3)<3 ? '0'x(3-length($3)) : '')/e;
Branch: 1 branch
BranchTrueFalseTotal
length $3 < 3 ? : 4 88 92
Condition100%2/2
$1 || '+'
l!l
2468
MC/DC100%1/1
$1 || '+'
$1
Truth table100%2/2
A
A= $1
Aresult
11
00
189 }
190 36 return join '', @a, '/';
191 }
192 4 ▶ return $val if $val =~ /^([-+]\d+(\.\d*)?){2,3}(CRS.*)?\/?$/; # already in ISO6709 format?
Branch: 1 branch
BranchTrueFalseTotal
if $val =~ m[^([-+]\d+(\.\d*)?){2,3}(CRS.*)?/?$] 0 4 4
193 4 return undef;
194 }
195  
196 #------------------------------------------------------------------------------
197 # Handle offsets in iloc (ItemLocation) atom when writing (ref ISO 14496-12:2015 pg.79)
198 # Inputs: 0) ExifTool ref, 1) dirInfo ref, 2) data ref, 3) output buffer ref
199 # Returns: true on success
200 # Notes: see also ParseItemLocation() in QuickTime.pm
201 # (variable names with underlines correspond to names in ISO 14496-12)
202 sub Handle_iloc($$$$)
203 3 ▶{
Subroutine Handle_iloc: called CC=39 SCAR=50.0
Pod undocumented
204 3 my ($et, $dirInfo, $dataPt, $outfile) = @_;
205 3 my ($i, $j, $num, $pos, $id);
206  
207 3 my $off = $$dirInfo{ChunkOffset};
208 3 my $len = length $$dataPt;
209 3 ▶ return 0 if $len < 8;
Branch: 1 branch
BranchTrueFalseTotal
if $len < 8 0 3 3
210 3 my $ver = Get8u($dataPt, 0);
211 3 my $siz = Get16u($dataPt, 4);
212 3 my $noff = ($siz >> 12);
213 3 my $nlen = ($siz >> 8) & 0x0f;
214 3 my $nbas = ($siz >> 4) & 0x0f;
215 3 my $nind = $siz & 0x0f;
216 3 my %ok = ( 0 => 1, 4 => 1, 8 => 8 );
217 3 ▶ return 0 unless $ok{$noff} and $ok{$nlen} and $ok{$nbas} and $ok{$nind};
Branch: 1 branch
BranchTrueFalseTotal
unless $ok{$noff} and $ok{$nlen} and $ok{$nbas} and $ok{$nind} 0 3 3
Condition33%3/9
$ok{$noff} and $ok{$nlen} and $ok{$nbas} and $ok{$nind}
!ll&&!rl&&r
003
$ok{$noff} and $ok{$nlen} and $ok{$nbas}
!ll&&!rl&&r
003
$ok{$noff} and $ok{$nlen}
!ll&&!rl&&r
003
MC/DC0%0/4
$ok{$noff} and $ok{$nlen} and $ok{$nbas} and $ok{$nind}
$ok{$noff} $ok{$nlen} $ok{$nbas} $ok{$nind}
Truth table20%1/5
A and B and C and D
A= $ok{$noff}B= $ok{$nlen}C= $ok{$nbas}D= $ok{$nind}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
218 # piggy-back on existing code to fix up stco/co64 4/8-byte offsets
219 3 ▶ my $tag = $noff == 4 ? 'stco_iloc' : 'co64_iloc';
Branch: 1 branch
BranchTrueFalseTotal
$noff == 4 ? : 3 0 3
220 3 ▶ if ($ver < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ver < 2) { } 3 0 3
221 3 $num = Get16u($dataPt, 6);
222 3 $pos = 8;
223 } else {
224 0 ▶ return 0 if $len < 10;
Branch: 1 branch
BranchTrueFalseTotal
if $len < 10 0 0 0
225 0 $num = Get32u($dataPt, 6);
226 0 $pos = 10;
227 }
228 3 ▶ for ($i=0; $i<$num; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $num) 9 3 12
229 9 ▶ if ($ver < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ver < 2) { } 9 0 9
230 9 ▶ return 0 if $pos + 2 > $len;
Branch: 1 branch
BranchTrueFalseTotal
if $pos + 2 > $len 0 9 9
231 9 $id = Get16u($dataPt, $pos);
232 9 $pos += 2;
233 } else {
234 0 ▶ return 0 if $pos + 4 > $len;
Branch: 1 branch
BranchTrueFalseTotal
if $pos + 4 > $len 0 0 0
235 0 $id = Get32u($dataPt, $pos);
236 0 $pos += 4;
237 }
238 9 my ($constOff, @offBase, @offItem, $minOffset);
239 9 ▶ if ($ver == 1 or $ver == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ver == 1 or $ver == 2) 0 9 9
Condition33%1/3
$ver == 1 or $ver == 2
l!l&&r!l&&!r
009
MC/DC0%0/2
$ver == 1 or $ver == 2
$ver == 1 $ver == 2
Truth table33%1/3
A or B
A= $ver == 1B= $ver == 2
ABresult
1X1
011
000
240 0 ▶ return 0 if $pos + 2 > $len;
Branch: 1 branch
BranchTrueFalseTotal
if $pos + 2 > $len 0 0 0
241 # offsets are absolute only if ConstructionMethod is 0, otherwise
242 # the relative offsets are constant as far as we are concerned
243 0 $constOff = Get16u($dataPt, $pos) & 0x0f;
244 0 $pos += 2;
245 }
246 9 ▶ return 0 if $pos + 2 > $len;
Branch: 1 branch
BranchTrueFalseTotal
if $pos + 2 > $len 0 9 9
247 9 my $drefIdx = Get16u($dataPt, $pos);
248 9 ▶ if ($drefIdx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($drefIdx) 0 9 9
249 0 ▶ if ($$et{QtDataRef} and $$et{QtDataRef}[$drefIdx - 1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{'QtDataRef'} and $et->{'QtDataRef'}[$drefIdx - 1]) { } 0 0 0
Condition0%0/3
$et->{"QtDataRef"} and $et->{"QtDataRef"}[$drefIdx - 1]
!ll&&!rl&&r
000
MC/DC0%0/2
$et->{"QtDataRef"} and $et->{"QtDataRef"}[$drefIdx - 1]
$et->{"QtDataRef"} $et->{"QtDataRef"}[$drefIdx - 1]
Truth table0%0/3
A and B
A= $et->{"QtDataRef"}B= $et->{"QtDataRef"}[$drefIdx - 1]
ABresult
0X0
100
111
250 0 my $dref = $$et{QtDataRef}[$drefIdx - 1];
251 # these offsets are constant unless the data is in this file
252 0 ▶ $constOff = 1 unless $$dref[1] == 1 and $$dref[0] ne 'rsrc';
Branch: 1 branch
BranchTrueFalseTotal
unless $dref->[1] == 1 and $dref->[0] ne "rsrc" 0 0 0
Condition0%0/3
$dref->[1] == 1 and $dref->[0] ne "rsrc"
!ll&&!rl&&r
000
MC/DC0%0/2
$dref->[1] == 1 and $dref->[0] ne "rsrc"
$dref->[1] == 1 $dref->[0] ne "rsrc"
Truth table0%0/3
A and B
A= $dref->[1] == 1B= $dref->[0] ne "rsrc"
ABresult
0X0
100
111
253 } else {
254 0 $et->Error("No data reference for iloc entry $i");
255 0 return 0;
256 }
257 }
258 9 $pos += 2;
259 # get base offset and save its location if in this file
260 9 my $base_offset = GetVarInt($dataPt, $pos, $nbas);
261 9 ▶ if ($base_offset and not $constOff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($base_offset and not $constOff) 6 3 9
Condition66%2/3
$base_offset and not $constOff
!ll&&!rl&&r
306
MC/DC50%1/2
$base_offset and not $constOff
$base_offset not $constOff
Truth table66%2/3
A and not(B)
A= $base_offsetB= not $constOff
ABresult
0X0
100
111
262 6 ▶ my $tg = ($nbas == 4 ? 'stco' : 'co64') . '_iloc';
Branch: 1 branch
BranchTrueFalseTotal
$nbas == 4 ? : 6 0 6
263 6 push @offBase, [ $tg, length($$outfile) + 8 + $pos - $nbas, $nbas, 0, $id ];
264 }
265 9 ▶ return 0 if $pos + 2 > $len;
Branch: 1 branch
BranchTrueFalseTotal
if $pos + 2 > $len 0 9 9
266 9 my $ext_num = Get16u($dataPt, $pos);
267 9 $pos += 2;
268 9 my $listStartPos = $pos;
269 # run through the item list to get offset locations and the minimum offset in this file
270 9 ▶ for ($j=0; $j<$ext_num; ++$j) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < $ext_num) 9 9 18
271 9 ▶ $pos += $nind if $ver == 1 or $ver == 2;
Branch: 1 branch
BranchTrueFalseTotal
if $ver == 1 or $ver == 2 0 9 9
Condition33%1/3
$ver == 1 or $ver == 2
l!l&&r!l&&!r
009
MC/DC0%0/2
$ver == 1 or $ver == 2
$ver == 1 $ver == 2
Truth table33%1/3
A or B
A= $ver == 1B= $ver == 2
ABresult
1X1
011
000
272 9 my $extent_offset = GetVarInt($dataPt, $pos, $noff);
273 9 ▶ return 0 unless defined $extent_offset;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $extent_offset 0 9 9
274 9 ▶ unless ($constOff) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($constOff) 9 0 9
275 9 ▶ push @offItem, [ $tag, length($$outfile) + 8 + $pos - $noff, $noff, 0, $id ] if $noff;
Branch: 1 branch
BranchTrueFalseTotal
if $noff 9 0 9
276 9 ▶ $minOffset = $extent_offset if not defined $minOffset or $minOffset > $extent_offset;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $minOffset or $minOffset > $extent_offset 9 0 9
Condition33%1/3
not defined $minOffset or $minOffset > $extent_offset
l!l&&r!l&&!r
900
MC/DC0%0/2
not defined $minOffset or $minOffset > $extent_offset
not defined $minOffset $minOffset > $extent_offset
Truth table33%1/3
not(A) or B
A= not defined $minOffsetB= $minOffset > $extent_offset
ABresult
1X1
011
000
277 }
278 9 ▶ return 0 if $pos + $nlen > length $$dataPt;
Branch: 1 branch
BranchTrueFalseTotal
if $pos + $nlen > length $$dataPt 0 9 9
279 9 $pos += $nlen;
280 }
281 # decide whether to fix up the base offset or individual item offsets
282 # (adjust the one that is larger)
283 9 ▶ if (defined $minOffset and $minOffset > $base_offset) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $minOffset and $minOffset > $base_offset) { } 3 6 9
Condition66%2/3
defined $minOffset and $minOffset > $base_offset
!ll&&!rl&&r
063
MC/DC50%1/2
defined $minOffset and $minOffset > $base_offset
defined $minOffset $minOffset > $base_offset
Truth table66%2/3
A and B
A= defined $minOffsetB= $minOffset > $base_offset
ABresult
0X0
100
111
284 3 $$_[3] = $base_offset foreach @offItem;
285 3 push @$off, @offItem;
286 } else {
287 6 $$_[3] = $minOffset foreach @offBase;
288 6 push @$off, @offBase;
289 }
290 }
291 3 return 1;
292 }
293  
294 #------------------------------------------------------------------------------
295 # Get localized version of tagInfo hash
296 # Inputs: 0) tagInfo hash ref, 1) language code (eg. "fra-FR")
297 # Returns: new tagInfo hash ref, or undef if invalid or no language code
298 sub GetLangInfo($$)
299 119 ▶{
Subroutine GetLangInfo: called CC=4 SCAR=14.2
Pod undocumented
300 119 my ($tagInfo, $langCode) = @_;
301 119 ▶ return undef unless $langCode;
Branch: 1 branch
BranchTrueFalseTotal
unless $langCode 0 119 119
302 # only allow alternate language tags in lang-alt lists
303 119 my $writable = $$tagInfo{Writable};
304 119 ▶ $writable = $$tagInfo{Table}{WRITABLE} unless defined $writable;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $writable 119 0 119
305 119 ▶ return undef unless $writable;
Branch: 1 branch
BranchTrueFalseTotal
unless $writable 0 119 119
306 119 $langCode =~ tr/_/-/; # RFC 3066 specifies '-' as a separator
307 119 my $langInfo = Image::ExifTool::GetLangInfo($tagInfo, $langCode);
308 119 return $langInfo;
309 }
310  
311 #------------------------------------------------------------------------------
312 # validate raw values for writing
313 # Inputs: 0) ExifTool ref, 1) tagInfo hash ref, 2) raw value ref
314 # Returns: error string or undef (and possibly changes value) on success
315 sub CheckQTValue($$$)
316 705 ▶{
Subroutine CheckQTValue: called CC=4 SCAR=13.9
Pod undocumented
317 705 my ($et, $tagInfo, $valPtr) = @_;
318 705 ▶ my $format = $$tagInfo{Format} || $$tagInfo{Writable} || $$tagInfo{Table}{FORMAT};
Condition100%6/6
$tagInfo->{'Format'} || $tagInfo->{'Writable'} || $tagInfo->{'Table'}{'FORMAT'}
l!l&&r!l&&!r
66469170
$tagInfo->{"Format"} or $tagInfo->{"Writable"}
l!l&&r!l&&!r
624639
MC/DC100%3/3
$tagInfo->{'Format'} || $tagInfo->{'Writable'} || $tagInfo->{'Table'}{'FORMAT'}
$tagInfo->{"Format"} $tagInfo->{"Writable"} $tagInfo->{'Table'}{'FORMAT'}
Truth table100%4/4
A or B || C
A= $tagInfo->{"Format"}B= $tagInfo->{"Writable"}C= $tagInfo->{'Table'}{'FORMAT'}
ABCresult
1XX1
01X1
0011
0000
319 705 ▶ return undef unless $format;
Branch: 1 branch
BranchTrueFalseTotal
unless $format 170 535 705
320 535 return Image::ExifTool::CheckValue($valPtr, $format, $$tagInfo{Count});
321 }
322  
323 #------------------------------------------------------------------------------
324 # Format QuickTime value for writing
325 # Inputs: 0) ExifTool ref, 1) value ref, 2) tagInfo ref, 3) Format (or undef)
326 # Returns: Flags for QT data type, and reformats value as required (sets to undef on error)
327 sub FormatQTValue($$;$$)
328 32 ▶{
Subroutine FormatQTValue: called CC=16 SCAR=34.6
Pod undocumented
329 32 my ($et, $valPt, $tagInfo, $format) = @_;
330 32 my $writable = $$tagInfo{Writable};
331 32 my $count = $$tagInfo{Count};
332 32 my $flags;
333 32 ▶ $format or $format = $$tagInfo{Format};
Branch: 1 branch
BranchTrueFalseTotal
$format or $format = $tagInfo->{"Format"} 0 32 32
334 32 ▶ if ($format and $format ne 'string' or not $format and $writable and $writable ne 'string') {
Branch: 4 branches
BranchTrueFalseTotal
if ($format and $format ne 'string' or not $format and $writable and $writable ne 'string') { } 2 30 32
elsif ($$valPt =~ /^\xff\xd8\xff/) { } 0 30 30
elsif ($$valPt =~ /^(\x89P|\x8aM|\x8bJ)NG\r\n\x1a\n/) { } 0 30 30
elsif ($$valPt =~ /^BM.{15}\0/s) { } 0 30 30
Condition58%7/12
$format and $format ne "string" or not $format and $writable and $writable ne "string"
l!l&&r!l&&!r
0230
$format and $format ne "string"
!ll&&!rl&&r
3200
not $format and $writable and $writable ne "string"
!ll&&!rl&&r
3002
not $format and $writable
!ll&&!rl&&r
0302
MC/DC20%1/5
$format and $format ne "string" or not $format and $writable and $writable ne "string"
$format $format ne "string" not $format $writable $writable ne "string"
Truth table22%2/9
A and B or not(C) and D and E
A= $formatB= $format ne "string"C= not $formatD= $writableE= $writable ne "string"
ABCDEresult
11XXX1
0X1111
101111
0X0XX0
0X10X0
0X1100
100XX0
1010X0
101100
335 2 ▶ $$valPt = WriteValue($$valPt, $format || $writable, $count);
Condition33%1/3
$format || $writable
l!l&&r!l&&!r
020
MC/DC0%0/2
$format || $writable
$format $writable
Truth table33%1/3
A || B
A= $formatB= $writable
ABresult
1X1
011
000
336 2 ▶ if ($writable and $qtFormat{$writable}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($writable and $qtFormat{$writable}) { } 0 2 2
Condition33%1/3
$writable and $qtFormat{$writable}
!ll&&!rl&&r
020
MC/DC0%0/2
$writable and $qtFormat{$writable}
$writable $qtFormat{$writable}
Truth table33%1/3
A and B
A= $writableB= $qtFormat{$writable}
ABresult
0X0
100
111
337 0 $flags = $qtFormat{$writable};
338 } else {
339 2 ▶ $flags = $qtFormat{$format || 0} || 0;
Condition50%2/4
$qtFormat{$format or 0} || 0
l!l
02
$format || 0
l!l
02
MC/DC0%0/1
$qtFormat{$format or 0} || 0
$qtFormat{$format or 0}
MC/DC0%0/1
$format || 0
$format
Truth table50%1/2
A
A= $qtFormat{$format or 0}
Aresult
11
00
Truth table50%1/2
A
A= $format
Aresult
11
00
340 }
341 } elsif ($$valPt =~ /^\xff\xd8\xff/) {
342 0 $flags = 0x0d; # JPG
343 } elsif ($$valPt =~ /^(\x89P|\x8aM|\x8bJ)NG\r\n\x1a\n/) {
344 0 $flags = 0x0e; # PNG
345 } elsif ($$valPt =~ /^BM.{15}\0/s) {
346 0 $flags = 0x1b; # BMP
347 } else {
348 30 $flags = 0x01; # UTF8
349 30 $$valPt = $et->Encode($$valPt, 'UTF8');
350 }
351 32 ▶ defined $$valPt or $et->Warn("Error converting value for $$tagInfo{Name}");
Branch: 1 branch
BranchTrueFalseTotal
defined $$valPt or $et->Warn(qq[Error converting value for $tagInfo->{"Name"}]) 32 0 32
352 32 return $flags;
353 }
354  
355 #------------------------------------------------------------------------------
356 # Set variable-length integer (used by WriteItemInfo)
357 # Inputs: 0) value, 1) integer size in bytes (0, 4 or 8),
358 # Returns: packed integer
359 sub SetVarInt($$)
360 6 ▶{
Subroutine SetVarInt: called CC=3 SCAR=15.1
Pod undocumented
361 6 my ($val, $n) = @_;
362 6 ▶ if ($n == 4) {
Branch: 2 branches
BranchTrueFalseTotal
if ($n == 4) { } 6 0 6
elsif ($n == 8) { } 0 0 0
363 6 return Set32u($val);
364 } elsif ($n == 8) {
365 0 return Set64u($val);
366 }
367 0 return '';
368 }
369  
370 #------------------------------------------------------------------------------
371 # Write Nextbase infi atom (ref PH)
372 # Inputs: 0) ExifTool object ref, 1) dirInfo ref, 2) tag table ref
373 # Returns: updated infi data
374 sub WriteNextbase($$$)
375 0 ▶{
Subroutine WriteNextbase: not called CC=3 SCAR=24.8
Pod undocumented
376 0 my ($et, $dirInfo, $tagTablePtr) = @_;
377 0 ▶ $et or return 1;
Branch: 1 branch
BranchTrueFalseTotal
$et or return 1 0 0 0
378 0 ▶ $$et{DEL_GROUP}{Nextbase} and ++$$et{CHANGED}, return '';
Branch: 1 branch
BranchTrueFalseTotal
$et->{"DEL_GROUP"}{"Nextbase"} and ++$et->{"CHANGED"}, (return "") 0 0 0
379 0 return ${$$dirInfo{DataPt}};
380 }
381  
382 #------------------------------------------------------------------------------
383 # Write Meta Keys to add/delete entries as necessary ('mdta' handler) (ref PH)
384 # Inputs: 0) ExifTool object ref, 1) dirInfo ref, 2) tag table ref
385 # Returns: updated keys box data
386 # Note: Residual entries may be left in the 'keys' directory when deleting tags
387 # with language codes because the language code(s) are not known until the
388 # corresponding ItemList entry(s) are processed
389 sub WriteKeys($$$)
390 228 ▶{
Subroutine WriteKeys: called CC=33 SCAR=37.0
Pod undocumented
391 228 my ($et, $dirInfo, $tagTablePtr) = @_;
392 228 ▶ $et or return 1; # allow dummy access to autoload this package
Branch: 1 branch
BranchTrueFalseTotal
$et or return 1 20 208 228
393 20 my $dataPt = $$dirInfo{DataPt};
394 20 my $dirLen = length $$dataPt;
395 20 my $outfile = $$dirInfo{OutFile};
396 20 my ($tag, %done, %remap, %info, %add, $i);
397  
398 20 ▶ my $keysGrp = $avType{$$et{MediaType}} ? "$avType{$$et{MediaType}}Keys" : 'Keys';
Branch: 1 branch
BranchTrueFalseTotal
$Image::ExifTool::QuickTime::avType{$et->{'MediaType'}} ? : 6 14 20
399 20 ▶ $dirLen < 8 and $et->Warn('Short Keys box'), $dirLen = 8, $$dataPt = "\0" x 8;
Branch: 1 branch
BranchTrueFalseTotal
$dirLen < 8 and $et->Warn("Short Keys box"), $dirLen = 8, $$dataPt = "\0\0\0\0\0\0\0\0" 0 20 20
400 20 ▶ if ($$et{DEL_GROUP}{$keysGrp}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"DEL_GROUP"}{$keysGrp}) 6 14 20
401 6 $dirLen = 8; # delete all existing keys
402 # deleted keys are identified by a zero entry in the Remap lookup
403 6 my $n = Get32u($dataPt, 4);
404 6 ▶ for ($i=1; $i<=$n; ++$i) { $remap{$i} = 0; }
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $n) 11 6 17
405 6 ▶ $et->VPrint(0, " [deleting $n $keysGrp entr".($n==1 ? 'y' : 'ies')."]\n");
Branch: 1 branch
BranchTrueFalseTotal
$n == 1 ? : 2 4 6
406 6 ++$$et{CHANGED};
407 }
408 20 my $pos = 8;
409 20 my $newTags = $et->GetNewTagInfoHash($tagTablePtr);
410 20 my $newData = substr($$dataPt, 0, $pos);
411  
412 20 my $newIndex = 1;
413 20 my $index = 1;
414 20 ▶ while ($pos < $dirLen - 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < $dirLen - 4) 25 20 45
415 25 my $len = unpack("x${pos}N", $$dataPt);
416 25 ▶ last if $len < 8 or $pos + $len > $dirLen;
Branch: 1 branch
BranchTrueFalseTotal
if $len < 8 or $pos + $len > $dirLen 0 25 25
Condition33%1/3
$len < 8 or $pos + $len > $dirLen
l!l&&r!l&&!r
0025
MC/DC0%0/2
$len < 8 or $pos + $len > $dirLen
$len < 8 $pos + $len > $dirLen
Truth table33%1/3
A or B
A= $len < 8B= $pos + $len > $dirLen
ABresult
1X1
011
000
417 25 my $ns = substr($$dataPt, $pos + 4, 4);
418 25 $tag = substr($$dataPt, $pos + 8, $len - 8);
419 25 $tag =~ s/\0.*//s; # truncate at null
420 25 ▶ $tag =~ s/^com\.apple\.quicktime\.// if $ns eq 'mdta'; # remove apple quicktime domain
Branch: 1 branch
BranchTrueFalseTotal
if $ns eq "mdta" 25 0 25
421 25 ▶ $tag = "Tag_$ns" unless $tag;
Branch: 1 branch
BranchTrueFalseTotal
unless $tag 0 25 25
422 25 $done{$tag} = 1; # set flag to avoid creating this tag
423 25 my $tagInfo = $et->GetTagInfo($tagTablePtr, $tag);
424 25 ▶ if ($tagInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo) 25 0 25
425 25 $info{$index} = $tagInfo;
426 25 ▶ if ($$newTags{$tag}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newTags->{$tag}) 2 23 25
427 2 my $nvHash = $et->GetNewValueHash($tagInfo);
428 # drop this tag if it is being deleted
429 2 ▶ if ($nvHash and $et->IsOverwriting($nvHash) > 0 and not defined $et->GetNewValue($nvHash)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nvHash and $et->IsOverwriting($nvHash) > 0 and not defined $et->GetNewValue($nvHash)) 1 1 2
Condition50%3/6
$nvHash and $et->IsOverwriting($nvHash) > 0 and not defined $et->GetNewValue($nvHash)
!ll&&!rl&&r
011
$nvHash and $et->IsOverwriting($nvHash) > 0
!ll&&!rl&&r
002
MC/DC33%1/3
$nvHash and $et->IsOverwriting($nvHash) > 0 and not defined $et->GetNewValue($nvHash)
$nvHash $et->IsOverwriting($nvHash) > 0 not defined $et->GetNewValue($nvHash)
Truth table50%2/4
A and B and not(C)
A= $nvHashB= $et->IsOverwriting($nvHash) > 0C= not defined $et->GetNewValue($nvHash)
ABCresult
0XX0
10X0
1100
1111
430 # don't delete this key if we could be writing any alternate-language version of this tag
431 1 my ($t, $dontDelete);
432 1 foreach $t (keys %$newTags) {
433 6 ▶ next unless $$newTags{$t}{SrcTagInfo} and $$newTags{$t}{SrcTagInfo} eq $tagInfo;
Branch: 1 branch
BranchTrueFalseTotal
unless $newTags->{$t}{"SrcTagInfo"} and $newTags->{$t}{"SrcTagInfo"} eq $tagInfo 6 0 6
Condition66%2/3
$newTags->{$t}{"SrcTagInfo"} and $newTags->{$t}{"SrcTagInfo"} eq $tagInfo
!ll&&!rl&&r
510
MC/DC0%0/2
$newTags->{$t}{"SrcTagInfo"} and $newTags->{$t}{"SrcTagInfo"} eq $tagInfo
$newTags->{$t}{"SrcTagInfo"} $newTags->{$t}{"SrcTagInfo"} eq $tagInfo
Truth table66%2/3
A and B
A= $newTags->{$t}{"SrcTagInfo"}B= $newTags->{$t}{"SrcTagInfo"} eq $tagInfo
ABresult
0X0
100
111
434 0 my $nv = $et->GetNewValueHash($$newTags{$t});
435 0 ▶ next unless $et->IsOverwriting($nv) and defined $et->GetNewValue($nv);
Branch: 1 branch
BranchTrueFalseTotal
unless $et->IsOverwriting($nv) and defined $et->GetNewValue($nv) 0 0 0
Condition0%0/3
$et->IsOverwriting($nv) and defined $et->GetNewValue($nv)
!ll&&!rl&&r
000
MC/DC0%0/2
$et->IsOverwriting($nv) and defined $et->GetNewValue($nv)
$et->IsOverwriting($nv) defined $et->GetNewValue($nv)
Truth table0%0/3
A and B
A= $et->IsOverwriting($nv)B= defined $et->GetNewValue($nv)
ABresult
0X0
100
111
436 0 $dontDelete = 1;
437 0 last;
438 }
439 1 ▶ unless ($dontDelete) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dontDelete) 1 0 1
440 # delete this key
441 1 $et->VPrint(1, "$$et{INDENT}\[deleting $keysGrp entry $index '${tag}']\n");
442 1 $pos += $len;
443 1 $remap{$index++} = 0;
444 1 ++$$et{CHANGED};
445 1 next;
446 }
447 }
448 }
449 }
450 # add to the Keys box data
451 24 $newData .= substr($$dataPt, $pos, $len);
452 24 $remap{$index++} = $newIndex++;
453 24 $pos += $len;
454 }
455 # add keys for any tags we need to create
456 20 foreach $tag (sort keys %$newTags) {
457 19 my $tagInfo = $$newTags{$tag};
458 19 my $id;
459 19 ▶ if ($$tagInfo{LangCode} and $$tagInfo{SrcTagInfo}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{'LangCode'} and $tagInfo->{'SrcTagInfo'}) { } 3 16 19
Condition66%2/3
$tagInfo->{"LangCode"} and $tagInfo->{"SrcTagInfo"}
!ll&&!rl&&r
1603
MC/DC50%1/2
$tagInfo->{"LangCode"} and $tagInfo->{"SrcTagInfo"}
$tagInfo->{"LangCode"} $tagInfo->{"SrcTagInfo"}
Truth table66%2/3
A and B
A= $tagInfo->{"LangCode"}B= $tagInfo->{"SrcTagInfo"}
ABresult
0X0
100
111
460 3 $id = $$tagInfo{SrcTagInfo}{TagID};
461 } else {
462 16 $id = $tag;
463 }
464 19 ▶ next if $done{$id};
Branch: 1 branch
BranchTrueFalseTotal
if $done{$id} 4 15 19
465 15 my $nvHash = $et->GetNewValueHash($tagInfo);
466 15 ▶ next unless $$nvHash{IsCreating} and $et->IsOverwriting($nvHash) and
Branch: 1 branch
BranchTrueFalseTotal
unless $nvHash->{"IsCreating"} and $et->IsOverwriting($nvHash) and defined $et->GetNewValue($nvHash) 4 11 15
Condition66%4/6
$nvHash->{"IsCreating"} and $et->IsOverwriting($nvHash) and defined $et->GetNewValue($nvHash)
!ll&&!rl&&r
4011
$nvHash->{"IsCreating"} and $et->IsOverwriting($nvHash)
!ll&&!rl&&r
4011
MC/DC33%1/3
$nvHash->{"IsCreating"} and $et->IsOverwriting($nvHash) and defined $et->GetNewValue($nvHash)
$nvHash->{"IsCreating"} $et->IsOverwriting($nvHash) defined $et->GetNewValue($nvHash)
Truth table50%2/4
A and B and C
A= $nvHash->{"IsCreating"}B= $et->IsOverwriting($nvHash)C= defined $et->GetNewValue($nvHash)
ABCresult
0XX0
10X0
1100
1111
467 defined $et->GetNewValue($nvHash);
468 # add new entry to 'keys' data
469 11 my $val = $id;
470 11 ▶ unless ($val =~ /^(.*?)\./ and $fullKeysID{$1}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($val =~ /^(.*?)\./ and $fullKeysID{$1}) 11 0 11
Condition66%2/3
$val =~ /^(.*?)\./ and $fullKeysID{$1}
!ll&&!rl&&r
650
MC/DC0%0/2
$val =~ /^(.*?)\./ and $fullKeysID{$1}
$val =~ /^(.*?)\./ $fullKeysID{$1}
Truth table66%2/3
A and B
A= $val =~ /^(.*?)\./B= $fullKeysID{$1}
ABresult
0X0
100
111
471 11 $val = "com.apple.quicktime.$val";
472 }
473 11 $newData .= Set32u(8 + length($val)) . 'mdta' . $val;
474 11 $et->VPrint(1, "$$et{INDENT}\[adding $keysGrp entry $newIndex '${id}']\n");
475 11 $add{$newIndex++} = $tagInfo;
476 11 ++$$et{CHANGED};
477 }
478 20 my $num = $newIndex - 1;
479 20 ▶ if ($num) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num) { } 16 4 20
480 16 Set32u($num, \$newData, 4); # update count in header
481 } else {
482 4 $newData = ''; # delete empty Keys box
483 }
484 # save temporary variables for use when writing ItemList:
485 # Remap - lookup for remapping Keys ID numbers (0 if item is deleted)
486 # Info - Keys tag information, based on old index value
487 # Add - Keys items deleted, based on old index value
488 # Num - Number of items in edited Keys box
489 20 $$et{$keysGrp} = { Remap => \%remap, Info => \%info, Add => \%add, Num => $num };
490  
491 20 return $newData; # return updated Keys box
492 }
493  
494 #------------------------------------------------------------------------------
495 # Write ItemInformation in HEIC files
496 # Inputs: 0) ExifTool ref, 1) dirInfo ref (with BoxPos entry), 2) output buffer ref
497 # Returns: mdat edit list ref (empty if nothing changed)
498 sub WriteItemInfo($$$)
499 3 ▶{
Subroutine WriteItemInfo: called CC=109 SCAR=70.7
Pod undocumented
500 3 my ($et, $dirInfo, $outfile) = @_;
501 3 my $boxPos = $$dirInfo{BoxPos}; # hash of [position,length,irefVer(iref only)] for box in $outfile
502 3 my $raf = $$et{RAF};
503 3 my $items = $$et{ItemInfo};
504 3 my (%did, @mdatEdit, $name, $tmap);
505  
506 3 ▶ return () unless $items and $raf;
Branch: 1 branch
BranchTrueFalseTotal
unless $items and $raf 0 3 3
Condition33%1/3
$items and $raf
!ll&&!rl&&r
003
MC/DC0%0/2
$items and $raf
$items $raf
Truth table33%1/3
A and B
A= $itemsB= $raf
ABresult
0X0
100
111
507  
508 # extract information from EXIF/XMP metadata items
509 3 my $primary = $$et{PrimaryItem};
510 3 my $curPos = $raf->Tell();
511 3 my $lastID = 0;
512 3 my $id;
513 3 foreach $id (sort { $a <=> $b } keys %$items) {
514 9 $lastID = $id;
515 9 ▶ $primary = $id unless defined $primary; # assume primary is lowest-number item if pitm missing
Branch: 1 branch
BranchTrueFalseTotal
unless defined $primary 0 9 9
516 9 my $item = $$items{$id};
517 # only edit primary EXIF/XMP metadata
518 9 ▶ next unless $$item{RefersTo} and $$item{RefersTo}{$primary};
Branch: 1 branch
BranchTrueFalseTotal
unless $item->{"RefersTo"} and $item->{"RefersTo"}{$primary} 6 3 9
Condition100%3/3
$item->{"RefersTo"} and $item->{"RefersTo"}{$primary}
!ll&&!rl&&r
333
MC/DC100%2/2
$item->{"RefersTo"} and $item->{"RefersTo"}{$primary}
$item->{"RefersTo"} $item->{"RefersTo"}{$primary}
Truth table100%3/3
A and B
A= $item->{"RefersTo"}B= $item->{"RefersTo"}{$primary}
ABresult
0X0
100
111
519 3 ▶ my $type = $$item{ContentType} || $$item{Type} || next;
Condition60%3/5
$item->{'ContentType'} || $item->{'Type'} || (next)
l!l
30
$item->{"ContentType"} or $item->{"Type"}
l!l&&r!l&&!r
210
MC/DC0%0/2
$item->{'ContentType'} || $item->{'Type'} || (next)
$item->{"ContentType"} $item->{"Type"}
Truth table66%2/3
A or B
A= $item->{"ContentType"}B= $item->{"Type"}
ABresult
1X1
011
000
520 3 ▶ $tmap = $id if $type eq 'tmap'; # save ID of primary 'tmap' item (tone-mapped image)
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "tmap" 0 3 3
521 # get ExifTool name for this item
522 3 $name = { Exif => 'EXIF', 'application/rdf+xml' => 'XMP' }->{$type};
523 3 ▶ next unless $name; # only care about EXIF and XMP
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 3 3
524 3 ▶ next unless $$et{EDIT_DIRS}{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless $et->{"EDIT_DIRS"}{$name} 0 3 3
525 3 $did{$name} = 1; # set flag to prevent creating this metadata
526 3 my ($warn, $extent, $buff, @edit);
527 3 ▶ $warn = 'Missing iloc box' unless $$boxPos{iloc};
Branch: 1 branch
BranchTrueFalseTotal
unless $boxPos->{"iloc"} 0 3 3
528 3 ▶ $warn = "No Extents for $type item" unless $$item{Extents} and @{$$item{Extents}};
Branch: 1 branch
BranchTrueFalseTotal
unless $item->{"Extents"} and @{$item->{"Extents"};} 0 3 3
Condition33%1/3
$item->{"Extents"} and @{$item->{"Extents"};}
!ll&&!rl&&r
003
MC/DC0%0/2
$item->{"Extents"} and @{$item->{"Extents"};}
$item->{"Extents"} @{$item->{"Extents"};}
Truth table33%1/3
A and B
A= $item->{"Extents"}B= @{$item->{"Extents"};}
ABresult
0X0
100
111
529 3 ▶ if ($$item{ContentEncoding}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item->{"ContentEncoding"}) 0 3 3
530 0 ▶ if ($$item{ContentEncoding} ne 'deflate') {
Branch: 2 branches
BranchTrueFalseTotal
if ($item->{'ContentEncoding'} ne 'deflate') { } 0 0 0
elsif (not eval { do { require Compress::Zlib } }) { } 0 0 0
531 0 $warn = "Can't currently decode $$item{ContentEncoding} encoded $type metadata";
532 0 } elsif (not eval { require Compress::Zlib }) {
533 0 $warn = "Install Compress::Zlib to decode deflated $type metadata";
534 }
535 }
536 3 ▶ $warn = "Can't currently decode protected $type metadata" if $$item{ProtectionIndex};
Branch: 1 branch
BranchTrueFalseTotal
if $item->{"ProtectionIndex"} 0 3 3
537 3 ▶ $warn = "Can't currently extract $type with construction method $$item{ConstructionMethod}" if $$item{ConstructionMethod};
Branch: 1 branch
BranchTrueFalseTotal
if $item->{"ConstructionMethod"} 0 3 3
538 3 ▶ $warn = "$type metadata is not in this file" if $$item{DataReferenceIndex};
Branch: 1 branch
BranchTrueFalseTotal
if $item->{"DataReferenceIndex"} 0 3 3
539 3 ▶ $warn and $et->Warn($warn), next;
Branch: 1 branch
BranchTrueFalseTotal
$warn and $et->Warn($warn), next 0 3 3
540 3 ▶ my $base = $$item{BaseOffset} || 0;
Condition50%1/2
$item->{'BaseOffset'} || 0
l!l
03
MC/DC0%0/1
$item->{'BaseOffset'} || 0
$item->{'BaseOffset'}
Truth table50%1/2
A
A= $item->{'BaseOffset'}
Aresult
11
00
541 3 my $val = '';
542 3 foreach $extent (@{$$item{Extents}}) {
543 3 ▶ $val .= $buff if defined $buff;
Branch: 1 branch
BranchTrueFalseTotal
if defined $buff 0 3 3
544 3 my $pos = $$extent[1] + $base;
545 3 ▶ if ($$extent[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($extent->[2]) { } 2 1 3
546 2 ▶ $raf->Seek($pos, 0) or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($pos, 0) or last 2 0 2
547 2 ▶ $raf->Read($buff, $$extent[2]) or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, $extent->[2]) or last 2 0 2
548 } else {
549 1 $buff = '';
550 }
551 3 push @edit, [ $pos, $pos + $$extent[2] ]; # replace or delete this if changed
552 }
553 3 ▶ next unless defined $buff;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $buff 0 3 3
554 3 ▶ $buff = $val . $buff if length $val;
Branch: 1 branch
BranchTrueFalseTotal
if length $val 0 3 3
555 3 my $comp = $et->Options('Compress');
556 3 ▶ if (defined $comp and ($comp xor $$item{ContentEncoding})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $comp and $comp ^^ $item->{"ContentEncoding"}) 0 3 3
Condition14%1/7
defined $comp and $comp ^^ $item->{"ContentEncoding"}
!ll&&!rl&&r
300
$comp xor $item->{"ContentEncoding"}
l&&rl&&!r!l&&r!l&&!r
0000
MC/DC0%0/3
defined $comp and $comp ^^ $item->{"ContentEncoding"}
defined $comp $comp $item->{"ContentEncoding"}
Truth table20%1/5
A and B xor C
A= defined $compB= $compC= $item->{"ContentEncoding"}
ABCresult
0XX0
1110
1000
1101
1011
557 #TODO: add ability to edit infe entry in iinf to change encoding according to Compress option if set
558 0 $et->Warn("Can't currently change compression when rewriting $name in HEIC",1);
559 }
560 3 my $wasDeflated;
561 3 ▶ if ($$item{ContentEncoding}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item->{"ContentEncoding"}) 0 3 3
562 0 my ($v2, $stat);
563 0 my $inflate = Compress::Zlib::inflateInit();
564 0 ▶ $inflate and ($v2, $stat) = $inflate->inflate($buff);
Branch: 1 branch
BranchTrueFalseTotal
$inflate and () = $inflate->inflate($buff) 0 0 0
565 0 $et->VPrint(0, " (Inflating stored $name metadata)\n");
566 0 ▶ if ($inflate and $stat == Compress::Zlib::Z_STREAM_END()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inflate and $stat == Compress::Zlib::Z_STREAM_END()) { } 0 0 0
Condition0%0/3
$inflate and $stat == Compress::Zlib::Z_STREAM_END()
!ll&&!rl&&r
000
MC/DC0%0/2
$inflate and $stat == Compress::Zlib::Z_STREAM_END()
$inflate $stat == Compress::Zlib::Z_STREAM_END()
Truth table0%0/3
A and B
A= $inflateB= $stat == Compress::Zlib::Z_STREAM_END()
ABresult
0X0
100
111
567 0 $buff = $v2;
568 0 $wasDeflated = 1;
569 } else {
570 0 $et->Warn("Error inflating $name metadata");
571 0 next;
572 }
573 }
574 3 my ($hdr, $subTable, $proc);
575 3 my $strt = 0;
576 3 ▶ if ($name eq 'EXIF') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq 'EXIF') { } 1 2 3
577 1 ▶ if (not length $buff) {
Branch: 3 branches
BranchTrueFalseTotal
if (not length $buff) { } 0 1 1
elsif ($buff =~ /^(MM\0\x2a|II\x2a\0)/) { } 0 1 1
elsif (length $buff >= 4 and length $buff >= 4 + unpack('N', $buff)) { } 1 0 1
578 # create EXIF from scratch
579 0 $hdr = "\0\0\0\x06Exif\0\0";
580 } elsif ($buff =~ /^(MM\0\x2a|II\x2a\0)/) {
581 0 $et->Warn('Missing Exif header');
582 0 $hdr = '';
583 ▶ } elsif (length($buff) >= 4 and length($buff) >= 4 + unpack('N',$buff)) {
Condition33%1/3
length $buff >= 4 and length $buff >= 4 + unpack("N", $buff)
!ll&&!rl&&r
001
MC/DC0%0/2
length $buff >= 4 and length $buff >= 4 + unpack("N", $buff)
length $buff >= 4 length $buff >= 4 + unpack("N", $buff)
Truth table33%1/3
A and B
A= length $buff >= 4B= length $buff >= 4 + unpack("N", $buff)
ABresult
0X0
100
111
584 1 $hdr = substr($buff, 0, 4 + unpack('N',$buff));
585 1 $strt = length $hdr;
586 } else {
587 0 $et->Warn('Invalid Exif header');
588 0 next;
589 }
590 1 $subTable = GetTagTable('Image::ExifTool::Exif::Main');
591 1 $proc = \&Image::ExifTool::WriteTIFF;
592 } else {
593 2 $hdr = '';
594 2 $subTable = GetTagTable('Image::ExifTool::XMP::Main');
595 }
596 3 my %dirInfo = (
597 DataPt => \$buff,
598 DataLen => length $buff,
599 DirStart => $strt,
600 DirLen => length($buff) - $strt,
601 );
602 3 my $changed = $$et{CHANGED};
603 3 my $newVal = $et->WriteDirectory(\%dirInfo, $subTable, $proc);
604 3 ▶ if (defined $newVal and $changed ne $$et{CHANGED} and
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newVal and $changed ne $et->{"CHANGED"} and $dirInfo{"DirLen"} || length $newVal) 3 0 3
Condition44%4/9
defined $newVal and $changed ne $et->{"CHANGED"} and $dirInfo{"DirLen"} || length $newVal
!ll&&!rl&&r
003
defined $newVal and $changed ne $et->{"CHANGED"}
!ll&&!rl&&r
003
$dirInfo{"DirLen"} or length $newVal
l!l&&r!l&&!r
120
MC/DC0%0/4
defined $newVal and $changed ne $et->{"CHANGED"} and $dirInfo{"DirLen"} || length $newVal
defined $newVal $changed ne $et->{"CHANGED"} $dirInfo{"DirLen"} length $newVal
Truth table40%2/5
A and B and C or D
A= defined $newValB= $changed ne $et->{"CHANGED"}C= $dirInfo{"DirLen"}D= length $newVal
ABCDresult
0XXX0
10XX0
11000
111X1
11011
605 # nothing changed if deleting an empty directory
606 ($dirInfo{DirLen} or length $newVal))
607 {
608 3 ▶ $newVal = $hdr . $newVal if length $hdr and length $newVal;
Branch: 1 branch
BranchTrueFalseTotal
if length $hdr and length $newVal 1 2 3
Condition66%2/3
length $hdr and length $newVal
!ll&&!rl&&r
201
MC/DC50%1/2
length $hdr and length $newVal
length $hdr length $newVal
Truth table66%2/3
A and B
A= length $hdrB= length $newVal
ABresult
0X0
100
111
609 3 ▶ if ($wasDeflated) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wasDeflated) 0 3 3
610 0 my $deflate = Compress::Zlib::deflateInit();
611 0 ▶ if ($deflate) {
Branch: 1 branch
BranchTrueFalseTotal
if ($deflate) 0 0 0
612 0 $et->VPrint(0, " (Re-deflating new $name metadata)\n");
613 0 $buff = $deflate->deflate($newVal);
614 0 ▶ if (defined $buff) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $buff) 0 0 0
615 0 $buff .= $deflate->flush();
616 0 $newVal = $buff;
617 }
618 }
619 }
620 3 $edit[0][2] = \$newVal; # replace the old chunk with the new data
621 3 $edit[0][3] = $id; # mark this chunk with the item ID
622 3 push @mdatEdit, @edit;
623 # update item extent_length
624 3 my $n = length $newVal;
625 3 foreach $extent (@{$$item{Extents}}) {
626 3 my ($nlen, $lenPt) = @$extent[3,4];
627 3 ▶ if ($nlen == 8) {
Branch: 2 branches
BranchTrueFalseTotal
if ($nlen == 8) { } 0 3 3
elsif ($n <= 4294967295) { } 3 0 3
628 0 Set64u($n, $outfile, $$boxPos{iloc}[0] + 8 + $lenPt);
629 } elsif ($n <= 0xffffffff) {
630 3 Set32u($n, $outfile, $$boxPos{iloc}[0] + 8 + $lenPt);
631 } else {
632 0 $et->Error("Can't yet promote iloc length to 64 bits");
633 0 return ();
634 }
635 3 $n = 0;
636 }
637 3 ▶ if (@{$$item{Extents}} != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$item->{"Extents"};} != 1) 0 3 3
638 0 $et->Error("Can't yet handle $name in multiple parts. Please submit sample for testing");
639 }
640 }
641 3 $$et{CHANGED} = $changed; # (will set this later if successful in editing mdat)
642 }
643 3 $raf->Seek($curPos, 0); # seek back to original position
644  
645 # add necessary metadata types if they didn't already exist
646 3 my ($countNew, %add, %usedID);
647 3 foreach $name ('EXIF','XMP') {
648 6 ▶ next if $did{$name} or not $$et{ADD_DIRS}{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $did{$name} or not $et->{"ADD_DIRS"}{$name} 4 2 6
Condition100%3/3
$did{$name} or not $et->{"ADD_DIRS"}{$name}
l!l&&r!l&&!r
312
MC/DC100%2/2
$did{$name} or not $et->{"ADD_DIRS"}{$name}
$did{$name} not $et->{"ADD_DIRS"}{$name}
Truth table100%3/3
A or not(B)
A= $did{$name}B= not $et->{"ADD_DIRS"}{$name}
ABresult
1X1
011
000
649 2 my @missing;
650 2 ▶ $$boxPos{$_} or push @missing, $_ foreach qw(iinf iloc);
Branch: 1 branch
BranchTrueFalseTotal
$boxPos->{$_} or push @missing, $_ 4 0 4
651 2 ▶ if (@missing) {
Branch: 1 branch
BranchTrueFalseTotal
if (@missing) 0 2 2
652 0 ▶ my $str = @missing > 1 ? join(' and ', @missing) . ' boxes' : "@missing box";
Branch: 1 branch
BranchTrueFalseTotal
@missing > 1 ? : 0 0 0
653 0 $et->Warn("Can't create $name. Missing expected $str");
654 0 last;
655 }
656 2 ▶ unless (defined $$et{PrimaryItem}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $et->{"PrimaryItem"}) 0 2 2
657 0 ▶ unless (defined $primary) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $primary) 0 0 0
658 0 $et->Warn("Can't create $name. No items to reference");
659 0 last;
660 }
661 # add new primary item reference box after hdrl box
662 0 ▶ if ($primary < 0x10000) {
Branch: 1 branch
BranchTrueFalseTotal
if ($primary < 65536) { } 0 0 0
663 0 $add{hdlr} = pack('Na4Nn', 14, 'pitm', 0, $primary);
664 } else {
665 0 $add{hdlr} = pack('Na4CCCCN', 16, 'pitm', 1, 0, 0, 0, $primary);
666 }
667 0 $et->Warn("Added missing PrimaryItemReference (for item $primary)", 1);
668 }
669 2 my $buff = '';
670 2 my ($hdr, $subTable, $proc);
671 2 ▶ if ($name eq 'EXIF') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq 'EXIF') { } 1 1 2
672 1 $hdr = "\0\0\0\x06Exif\0\0";
673 1 $subTable = GetTagTable('Image::ExifTool::Exif::Main');
674 1 $proc = \&Image::ExifTool::WriteTIFF;
675 } else {
676 1 $hdr = '';
677 1 $subTable = GetTagTable('Image::ExifTool::XMP::Main');
678 }
679 2 my %dirInfo = (
680 DataPt => \$buff,
681 DataLen => 0,
682 DirStart => 0,
683 DirLen => 0,
684 );
685 2 my $changed = $$et{CHANGED};
686 2 my $newVal = $et->WriteDirectory(\%dirInfo, $subTable, $proc);
687 2 ▶ if (defined $newVal and $changed ne $$et{CHANGED}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newVal and $changed ne $et->{"CHANGED"}) 2 0 2
Condition33%1/3
defined $newVal and $changed ne $et->{"CHANGED"}
!ll&&!rl&&r
002
MC/DC0%0/2
defined $newVal and $changed ne $et->{"CHANGED"}
defined $newVal $changed ne $et->{"CHANGED"}
Truth table33%1/3
A and B
A= defined $newValB= $changed ne $et->{"CHANGED"}
ABresult
0X0
100
111
688 2 my $irefVer;
689 2 ▶ if ($$boxPos{iref}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($boxPos->{'iref'}) { } 2 0 2
690 2 $irefVer = Get8u($outfile, $$boxPos{iref}[0] + 8);
691 } else {
692 # create iref box after end of iinf box (and save version in boxPos list)
693 0 ▶ $irefVer = ($primary < 0x10000 ? 0 : 1);
Branch: 1 branch
BranchTrueFalseTotal
$primary < 65536 ? : 0 0 0
694 0 $$boxPos{iref} = [ $$boxPos{iinf}[0] + $$boxPos{iinf}[1], 0, $irefVer ];
695 }
696 2 ▶ $newVal = $hdr . $newVal if length $hdr;
Branch: 1 branch
BranchTrueFalseTotal
if length $hdr 1 1 2
697 # add new infe to iinf
698 2 ▶ $add{iinf} = $add{iref} = $add{iloc} = '' unless defined $add{iinf};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $add{"iinf"} 2 0 2
699 2 my ($type, $mime);
700 2 my $enc = '';
701 2 ▶ if ($name eq 'XMP') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq 'XMP') { } 1 1 2
702 1 $type = "mime\0";
703 1 $mime = "application/rdf+xml\0";
704 # write compressed XMP if Compress option is set
705 1 ▶ if ($et->Options('Compress') and length $newVal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->Options("Compress") and length $newVal) 0 1 1
Condition33%1/3
$et->Options("Compress") and length $newVal
!ll&&!rl&&r
100
MC/DC0%0/2
$et->Options("Compress") and length $newVal
$et->Options("Compress") length $newVal
Truth table33%1/3
A and B
A= $et->Options("Compress")B= length $newVal
ABresult
0X0
100
111
706 0 ▶ if (not eval { require Compress::Zlib }) {
Branch: 1 branch
BranchTrueFalseTotal
if (not eval { do { require Compress::Zlib } }) { } 0 0 0
707 0 $et->Warn('Install Compress::Zlib to write compressed metadata');
708 } else {
709 0 my $deflate = Compress::Zlib::deflateInit();
710 0 ▶ if ($deflate) {
Branch: 1 branch
BranchTrueFalseTotal
if ($deflate) 0 0 0
711 0 $et->VPrint(0, " (Deflating new $name metadata)\n");
712 0 my $buff = $deflate->deflate($newVal);
713 0 ▶ if (defined $buff) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $buff) 0 0 0
714 0 $newVal = $buff . $deflate->flush();
715 0 $enc = "deflate\0";
716 }
717 }
718 }
719 }
720 } else {
721 1 $type = "Exif\0";
722 1 $mime = '';
723 }
724 2 my $id = ++$lastID; # use next highest available ID (so ID's in iinf are in order)
725 #[retracted] # create new item information hash to save infe box in case we need it for sorting
726 #[retracted] my $item = $$items{$id} = { };
727 # add new infe entry to iinf box
728 2 my $n = length($type) + length($mime) + length($enc) + 16;
729 2 ▶ if ($id < 0x10000) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id < 65536) { } 2 0 2
730 2 $add{iinf} .= pack('Na4CCCCnn', $n, 'infe', 2, 0, 0, 1, $id, 0) . $type . $mime . $enc;
731 } else {
732 0 $n += 2;
733 0 $add{iinf} .= pack('Na4CCCCNn', $n, 'infe', 3, 0, 0, 1, $id, 0) . $type . $mime . $enc;
734 }
735 #[retracted] $add{iinf} .= $$item{infe};
736 # add new cdsc to iref (also refer to primary 'tmap' if it exists)
737 2 ▶ if ($irefVer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($irefVer) { } 0 2 2
738 0 ▶ my ($fmt, $siz, $num) = defined $tmap ? ('N', 22, 2) : ('', 18, 1);
Branch: 1 branch
BranchTrueFalseTotal
defined $tmap ? : 0 0 0
739 0 $add{iref} .= pack('Na4NnN'.$fmt, $siz, 'cdsc', $id, $num, $primary, $tmap);
740 } else {
741 2 ▶ my ($fmt, $siz, $num) = defined $tmap ? ('n', 16, 2) : ('', 14, 1);
Branch: 1 branch
BranchTrueFalseTotal
defined $tmap ? : 0 2 2
742 2 $add{iref} .= pack('Na4nnn'.$fmt, $siz, 'cdsc', $id, $num, $primary, $tmap);
743 }
744 # add new entry to iloc table (see ISO14496-12:2015 pg.79)
745 2 my $ilocVer = Get8u($outfile, $$boxPos{iloc}[0] + 8);
746 2 my $siz = Get16u($outfile, $$boxPos{iloc}[0] + 12); # get size information
747 2 my $noff = ($siz >> 12);
748 2 my $nlen = ($siz >> 8) & 0x0f;
749 2 my $nbas = ($siz >> 4) & 0x0f;
750 2 my $nind = $siz & 0x0f;
751 2 my ($pbas, $poff);
752 2 ▶ if ($ilocVer == 0) {
Branch: 3 branches
BranchTrueFalseTotal
if ($ilocVer == 0) { } 2 0 2
elsif ($ilocVer == 1) { } 0 0 0
elsif ($ilocVer == 2) { } 0 0 0
753 # set offset to 0 as flag that this is a new idat chunk being added
754 2 $pbas = length($add{iloc}) + 4;
755 2 $poff = $pbas + $nbas + 2;
756 2 $add{iloc} .= pack('nn',$id,0) . SetVarInt(0,$nbas) . Set16u(1) .
757 SetVarInt(0,$noff) . SetVarInt(length($newVal),$nlen);
758 } elsif ($ilocVer == 1) {
759 0 $pbas = length($add{iloc}) + 6;
760 0 $poff = $pbas + $nbas + 2 + $nind;
761 0 $add{iloc} .= pack('nnn',$id,0,0) . SetVarInt(0,$nbas) . Set16u(1) . SetVarInt(0,$nind) .
762 SetVarInt(0,$noff) . SetVarInt(length($newVal),$nlen);
763 } elsif ($ilocVer == 2) {
764 0 $pbas = length($add{iloc}) + 8;
765 0 $poff = $pbas + $nbas + 2 + $nind;
766 0 $add{iloc} .= pack('Nnn',$id,0,0) . SetVarInt(0,$nbas) . Set16u(1) . SetVarInt(0,$nind) .
767 SetVarInt(0,$noff) . SetVarInt(length($newVal),$nlen);
768 } else {
769 0 $et->Warn("Can't create $name. Unsupported iloc version $ilocVer");
770 0 last;
771 }
772 # add new ChunkOffset entry to update this new offset
773 2 ▶ my $off = $$dirInfo{ChunkOffset} or $et->Warn('Internal error. Missing ChunkOffset'), last;
Branch: 1 branch
BranchTrueFalseTotal
my $off = $dirInfo->{"ChunkOffset"} or $et->Warn("Internal error. Missing ChunkOffset"), last 2 0 2
774 2 my $newOff;
775 2 ▶ if ($noff == 4) {
Branch: 3 branches
BranchTrueFalseTotal
if ($noff == 4) { } 2 0 2
elsif ($noff == 8) { } 0 0 0
elsif ($noff == 0) { } 0 0 0
776 2 $newOff = [ 'stco_iloc', $$boxPos{iloc}[0] + $$boxPos{iloc}[1] + $poff, $noff, 0, $id ];
777 } elsif ($noff == 8) {
778 0 $newOff = [ 'co64_iloc', $$boxPos{iloc}[0] + $$boxPos{iloc}[1] + $poff, $noff, 0, $id ];
779 } elsif ($noff == 0) {
780 # offset_size is zero, so store the offset in base_offset instead
781 0 ▶ if ($nbas == 4) {
Branch: 2 branches
BranchTrueFalseTotal
if ($nbas == 4) { } 0 0 0
elsif ($nbas == 8) { } 0 0 0
782 0 $newOff = [ 'stco_iloc', $$boxPos{iloc}[0] + $$boxPos{iloc}[1] + $pbas, $nbas, 0, $id ];
783 } elsif ($nbas == 8) {
784 0 $newOff = [ 'co64_iloc', $$boxPos{iloc}[0] + $$boxPos{iloc}[1] + $pbas, $nbas, 0, $id ];
785 } else {
786 0 $et->Warn("Can't create $name. Invalid iloc offset+base size");
787 0 last;
788 }
789 } else {
790 0 $et->Warn("Can't create $name. Invalid iloc offset size");
791 0 last;
792 }
793 # add directory as a new mdat chunk
794 2 push @$off, $newOff;
795 2 push @mdatEdit, [ 0, 0, \$newVal, $id ];
796 2 $usedID{$id} = 1;
797 2 ▶ $countNew = ($countNew || 0) + 1;
Condition50%1/2
$countNew || 0
l!l
02
MC/DC0%0/1
$countNew || 0
$countNew
Truth table50%1/2
A
A= $countNew
Aresult
11
00
798 2 $$et{CHANGED} = $changed; # set this later if successful in editing mdat
799 }
800 }
801 3 ▶ if ($countNew) {
Branch: 1 branch
BranchTrueFalseTotal
if ($countNew) 2 1 3
802 # insert new entries into iinf, iref and iloc boxes,
803 # and add new pitm box after hdlr if necessary
804 2 my $added = 0;
805 2 my $tag;
806 2 foreach $tag (sort { $$boxPos{$a}[0] <=> $$boxPos{$b}[0] } keys %$boxPos) {
807 12 $$boxPos{$tag}[0] += $added;
808 12 ▶ next unless $add{$tag};
Branch: 1 branch
BranchTrueFalseTotal
unless $add{$tag} 6 6 12
809 6 my $pos = $$boxPos{$tag}[0];
810 6 ▶ unless ($$boxPos{$tag}[1]) {
Branch: 2 branches
BranchTrueFalseTotal
if ($boxPos->{$tag}[1]) { } 6 0 6
if (do { $tag ne "hdlr" }) 6 0 6
811 0 ▶ $tag eq 'iref' or $et->Error('Internal error adding iref box'), last;
Branch: 1 branch
BranchTrueFalseTotal
$tag eq "iref" or $et->Error("Internal error adding iref box"), last 0 0 0
812 # create new iref box
813 $add{$tag} = Set32u(12 + length $add{$tag}) . $tag .
814 0 Set8u($$boxPos{$tag}[2]) . "\0\0\0" . $add{$tag};
815 0 } elsif ($tag ne 'hdlr') {
816 6 my $n = Get32u($outfile, $pos) + length($add{$tag});
817 6 Set32u($n, $outfile, $pos); # increase box size
818 }
819 6 ▶ if ($tag eq 'iinf') {
Branch: 4 branches
BranchTrueFalseTotal
if ($tag eq 'iinf') { } 2 4 6
elsif ($tag eq 'iref') { } 2 2 4
elsif ($tag eq 'iloc') { } 2 0 2
elsif ($tag ne 'hdlr') { } 0 0 0
820 2 my $iinfVer = Get8u($outfile, $pos + 8);
821 2 ▶ if ($iinfVer == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($iinfVer == 0) { } 0 2 2
822 0 my $n = Get16u($outfile, $pos + 12) + $countNew;
823 0 ▶ if ($n > 0xffff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n > 65535) 0 0 0
824 0 $et->Error("Can't currently handle rollover to long item count");
825 0 return undef;
826 }
827 0 Set16u($n, $outfile, $pos + 12); # incr count
828 } else {
829 2 my $n = Get32u($outfile, $pos + 12) + $countNew;
830 2 Set32u($n, $outfile, $pos + 12); # incr count
831 }
832 } elsif ($tag eq 'iref') {
833 # nothing more to do
834 } elsif ($tag eq 'iloc') {
835 2 my $ilocVer = Get8u($outfile, $pos + 8);
836 2 ▶ if ($ilocVer < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ilocVer < 2) { } 2 0 2
837 2 my $n = Get16u($outfile, $pos + 14) + $countNew;
838 2 Set16u($n, $outfile, $pos + 14); # incr count
839 2 ▶ if ($n > 0xffff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n > 65535) 0 2 2
840 0 $et->Error("Can't currently handle rollover to long item count");
841 0 return undef;
842 }
843 } else {
844 0 my $n = Get32u($outfile, $pos + 14) + $countNew;
845 0 Set32u($n, $outfile, $pos + 14); # incr count
846 }
847 # must also update pointer locations in this box
848 2 ▶ if ($added) {
Branch: 1 branch
BranchTrueFalseTotal
if ($added) 0 2 2
849 0 $$_[1] += $added foreach @{$$dirInfo{ChunkOffset}};
850 }
851 } elsif ($tag ne 'hdlr') {
852 0 next;
853 }
854 # add new entries to this box (or add pitm after hdlr)
855 6 substr($$outfile, $pos + $$boxPos{$tag}[1], 0) = $add{$tag};
856 6 $$boxPos{$tag}[1] += length $add{$tag};
857 6 $added += length $add{$tag}; # positions are shifted by length of new entries
858 }
859 }
860 #[This sorting idea was retracted because just sorting 'iinf' wasn't sufficient to
861 # repair the problem where an out-of-order ID was added -- Apple Preview still
862 # ignores the gain-map image. It looks like either or both 'iref' and 'iloc' must
863 # also be sorted by ID, although the spec doesn't mention this]
864 #[retracted] # sort infe entries in iinf box if necessary
865 #[retracted] if ($$et{ItemsNotSorted}) {
866 #[retracted] if ($$boxPos{iinf}) {
867 #[retracted] my $iinfVer = Get8u($outfile, $$boxPos{iinf}[0] + 8);
868 #[retracted] my $off = $iinfVer == 0 ? 14 : 16; # offset to first infe item
869 #[retracted] my $sorted = ''; # sorted iinf payload
870 #[retracted] $sorted .= $$items{$_}{infe} || '' foreach sort { $a <=> $b } keys %$items;
871 #[retracted] if (length $sorted == $$boxPos{iinf}[1]-$off) {
872 #[retracted] # replace with sorted infe entries
873 #[retracted] substr($$outfile, $$boxPos{iinf}[0] + $off, length $sorted) = $sorted;
874 #[retracted] $et->Warn('Item info entries are out of order. Fixed.');
875 #[retracted] ++$$et{CHANGED};
876 #[retracted] } else {
877 #[retracted] $et->Warn('Error sorting item info entries');
878 #[retracted] }
879 #[retracted] } else {
880 #[retracted] $et->Warn('Item info entries are out of order');
881 #[retracted] }
882 #[retracted] delete $$et{ItemsNotSorted};
883 #[retracted] }
884 3 delete $$et{ItemInfo};
885 3 ▶ return @mdatEdit ? \@mdatEdit : undef;
Branch: 1 branch
BranchTrueFalseTotal
@mdatEdit ? : 3 0 3
886 }
887  
888 #------------------------------------------------------------------------------
889 # Write a series of QuickTime atoms from file or in memory
890 # Inputs: 0) ExifTool ref, 1) dirInfo ref, 2) tag table ref
891 # Returns: A) if dirInfo contains DataPt: new directory data
892 # B) otherwise: true on success, 0 if a write error occurred
893 # (true but sets an Error on a file format error)
894 # Notes: Yes, this is a real mess. Just like the QuickTime metadata situation.
895 sub WriteQuickTime($$$)
896 1037 ▶{
Subroutine WriteQuickTime: called CC=552 SCAR=96.9
Pod undocumented
897 1037 local $_;
898 1037 my ($et, $dirInfo, $tagTablePtr) = @_;
899 1037 ▶ $et or return 1; # allow dummy access to autoload this package
Branch: 1 branch
BranchTrueFalseTotal
$et or return 1 412 625 1037
900 412 my ($mdat, @mdat, @mdatEdit, $edit, $track, $outBuff, $co, $term, $delCount);
901 412 my (%langTags, $canCreate, $delGrp, %boxPos, %didDir, $writeLast, $err, $atomCount);
902 412 my ($tag, $lastTag, $lastPos, $errStr, $trailer, $buf2, $keysGrp, $keysPath, $itemIndex);
903 412 ▶ my $outfile = $$dirInfo{OutFile} || return 0;
Condition50%1/2
$dirInfo->{'OutFile'} || (return 0)
l!l
4120
MC/DC0%0/1
$dirInfo->{'OutFile'} || (return 0)
$dirInfo->{'OutFile'}
Truth table50%1/2
A
A= $dirInfo->{'OutFile'}
Aresult
11
00
904 412 my $raf = $$dirInfo{RAF}; # (will be null for lower-level atoms)
905 412 my $dataPt = $$dirInfo{DataPt}; # (will be null for top-level atoms)
906 412 my $dirName = $$dirInfo{DirName};
907 412 ▶ my $dirStart = $$dirInfo{DirStart} || 0;
Condition100%2/2
$dirInfo->{'DirStart'} || 0
l!l
70342
MC/DC100%1/1
$dirInfo->{'DirStart'} || 0
$dirInfo->{'DirStart'}
Truth table100%2/2
A
A= $dirInfo->{'DirStart'}
Aresult
11
00
908 412 my $parent = $$dirInfo{Parent};
909 412 my $addDirs = $$et{ADD_DIRS};
910 412 my $didTag = $$et{DidTag};
911 412 my $newTags = { };
912 412 my $createKeys = 0;
913 412 ▶ my ($rtnVal, $rtnErr) = $dataPt ? (undef, undef) : (1, 0);
Branch: 1 branch
BranchTrueFalseTotal
$dataPt ? : 389 23 412
914  
915 # check for trailer at end of file
916 412 ▶ if ($raf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raf) 23 389 412
917 23 $trailer = IdentifyTrailers($raf);
918 23 ▶ $trailer and not ref $trailer and $et->Error($trailer), return 1;
Branch: 1 branch
BranchTrueFalseTotal
$trailer and not ref $trailer and $et->Error($trailer), (return 1) 0 23 23
Condition33%1/3
$trailer and not ref $trailer
!ll&&!rl&&r
2300
MC/DC0%0/2
$trailer and not ref $trailer
$trailer not ref $trailer
Truth table33%1/3
A and not(B)
A= $trailerB= not ref $trailer
ABresult
0X0
100
111
919 }
920 412 ▶ if ($dataPt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dataPt) { } 389 23 412
921 389 $raf = File::RandomAccess->new($dataPt);
922 } else {
923 23 ▶ return 0 unless $raf;
Branch: 1 branch
BranchTrueFalseTotal
unless $raf 0 23 23
924 }
925 # use buffered output for everything but 'mdat' atoms
926 412 $outBuff = '';
927 412 $outfile = \$outBuff;
928  
929 412 ▶ $raf->Seek($dirStart, 1) if $dirStart; # skip header if it exists
Branch: 1 branch
BranchTrueFalseTotal
if $dirStart 70 342 412
930  
931 412 ▶ if ($avType{$$et{MediaType}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Image::ExifTool::QuickTime::avType{$et->{'MediaType'}}) { } 172 240 412
932 # (note: these won't be correct now if we haven't yet processed the Media box,
933 # but in this case they won't be needed until after we set them properly below)
934 172 ($keysGrp, $keysPath) = ("$avType{$$et{MediaType}}Keys", 'MOV-Movie-Track');
935 } else {
936 240 ($keysGrp, $keysPath) = ('Keys', 'MOV-Movie');
937 }
938 412 my $curPath = join '-', @{$$et{PATH}};
939 412 my ($dir, $writePath) = ($dirName, $dirName);
940 412 ▶ $writePath = "$dir-$writePath" while defined($dir = $$et{DirMap}{$dir});
Branch: 1 branch
BranchTrueFalseTotal
defined($dir = $et->{"DirMap"}{$dir}) and do { $writePath = "$dir-$writePath" } 398 412 810
941 # hack to create Keys directories if necessary (its containing Meta is in a different location)
942 412 ▶ if (($$addDirs{Keys} and $curPath =~ /^MOV-Movie(-Meta)?$/)) {
Branch: 3 branches
BranchTrueFalseTotal
if ($addDirs->{'Keys'} and $curPath =~ /^MOV-Movie(-Meta)?$/) { } 12 400 412
elsif ($addDirs->{'AudioKeys'} || $addDirs->{'VideoKeys'} and $curPath =~ /^MOV-Movie-Track(-Meta)?$/) { } 8 392 400
elsif ($curPath eq 'MOV-Movie-Meta-ItemList' or $curPath eq 'MOV-Movie-Track-Meta-ItemList' and $Image::ExifTool::QuickTime::avType{$et->{'MediaType'}}) { } 20 372 392
Condition100%3/3
$addDirs->{"Keys"} and $curPath =~ /^MOV-Movie(-Meta)?$/
!ll&&!rl&&r
3099112
MC/DC100%2/2
$addDirs->{"Keys"} and $curPath =~ /^MOV-Movie(-Meta)?$/
$addDirs->{"Keys"} $curPath =~ /^MOV-Movie(-Meta)?$/
Truth table100%3/3
A and B
A= $addDirs->{"Keys"}B= $curPath =~ /^MOV-Movie(-Meta)?$/
ABresult
0X0
100
111
943 12 $createKeys = 1; # create new Keys directories
944 ▶ } elsif (($$addDirs{AudioKeys} or $$addDirs{VideoKeys}) and $curPath =~ /^MOV-Movie-Track(-Meta)?$/) {
Condition83%5/6
$addDirs->{"AudioKeys"} || $addDirs->{"VideoKeys"} and $curPath =~ /^MOV-Movie-Track(-Meta)?$/
!ll&&!rl&&r
365278
$addDirs->{"AudioKeys"} or $addDirs->{"VideoKeys"}
l!l&&r!l&&!r
350365
MC/DC66%2/3
$addDirs->{"AudioKeys"} || $addDirs->{"VideoKeys"} and $curPath =~ /^MOV-Movie-Track(-Meta)?$/
$addDirs->{"AudioKeys"} $addDirs->{"VideoKeys"} $curPath =~ /^MOV-Movie-Track(-Meta)?$/
Truth table60%3/5
A or B and C
A= $addDirs->{"AudioKeys"}B= $addDirs->{"VideoKeys"}C= $curPath =~ /^MOV-Movie-Track(-Meta)?$/
ABCresult
00X0
1X00
0100
1X11
0111
945 8 $createKeys = -1; # (must wait until MediaType is known)
946 ▶ } elsif (($curPath eq 'MOV-Movie-Meta-ItemList') or
Condition83%5/6
$curPath eq "MOV-Movie-Meta-ItemList" or $curPath eq "MOV-Movie-Track-Meta-ItemList" and $Image::ExifTool::QuickTime::avType{$et->{"MediaType"}}
l!l&&r!l&&!r
146372
$curPath eq "MOV-Movie-Track-Meta-ItemList" and $Image::ExifTool::QuickTime::avType{$et->{"MediaType"}}
!ll&&!rl&&r
37206
MC/DC66%2/3
$curPath eq "MOV-Movie-Meta-ItemList" or $curPath eq "MOV-Movie-Track-Meta-ItemList" and $Image::ExifTool::QuickTime::avType{$et->{"MediaType"}}
$curPath eq "MOV-Movie-Meta-ItemList" $curPath eq "MOV-Movie-Track-Meta-ItemList" $Image::ExifTool::QuickTime::avType{$et->{"MediaType"}}
Truth table75%3/4
A or B and C
A= $curPath eq "MOV-Movie-Meta-ItemList"B= $curPath eq "MOV-Movie-Track-Meta-ItemList"C= $Image::ExifTool::QuickTime::avType{$et->{"MediaType"}}
ABCresult
1XX1
0111
00X0
0100
947 ($curPath eq 'MOV-Movie-Track-Meta-ItemList' and $avType{$$et{MediaType}}))
948 {
949 20 $createKeys = 2; # create new Keys tags
950 20 my $keys = $$et{$keysGrp};
951 20 ▶ if ($keys) {
Branch: 1 branch
BranchTrueFalseTotal
if ($keys) 20 0 20
952 # add new tag entries for existing Keys tags, now that we know their ID's
953 # - first make lookup to convert Keys tagInfo ref to index number
954 20 my ($index, %keysInfo);
955 20 foreach $index (keys %{$$keys{Info}}) {
956 25 ▶ $keysInfo{$$keys{Info}{$index}} = $index if $$keys{Remap}{$index};
Branch: 1 branch
BranchTrueFalseTotal
if $keys->{"Remap"}{$index} 24 1 25
957 }
958 20 my $keysTable = GetTagTable("Image::ExifTool::QuickTime::$keysGrp");
959 20 my $newKeysTags = $et->GetNewTagInfoHash($keysTable);
960 20 foreach (keys %$newKeysTags) {
961 19 my $tagInfo = $$newKeysTags{$_};
962 19 ▶ $index = $keysInfo{$tagInfo} || ($$tagInfo{SrcTagInfo} and $keysInfo{$$tagInfo{SrcTagInfo}});
Condition100%6/6
$keysInfo{$tagInfo} || $tagInfo->{'SrcTagInfo'} && $keysInfo{$tagInfo->{'SrcTagInfo'}}
l!l&&r!l&&!r
1216
$tagInfo->{"SrcTagInfo"} and $keysInfo{$tagInfo->{"SrcTagInfo"}}
!ll&&!rl&&r
1512
MC/DC100%3/3
$keysInfo{$tagInfo} || $tagInfo->{'SrcTagInfo'} && $keysInfo{$tagInfo->{'SrcTagInfo'}}
$keysInfo{$tagInfo} $tagInfo->{"SrcTagInfo"} $keysInfo{$tagInfo->{"SrcTagInfo"}}
Truth table100%4/4
A || B and C
A= $keysInfo{$tagInfo}B= $tagInfo->{"SrcTagInfo"}C= $keysInfo{$tagInfo->{"SrcTagInfo"}}
ABCresult
1XX1
0111
00X0
0100
963 19 ▶ next unless $index;
Branch: 1 branch
BranchTrueFalseTotal
unless $index 16 3 19
964 3 my $id = Set32u($index);
965 3 ▶ if ($$tagInfo{LangCode}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{"LangCode"}) 2 1 3
966 # add to lookup of language tags we are writing with this ID
967 2 ▶ $langTags{$id} = { } unless $langTags{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless $langTags{$id} 2 0 2
968 2 $langTags{$id}{$_} = $tagInfo;
969 2 $id .= '-' . $$tagInfo{LangCode};
970 }
971 3 $$newTags{$id} = $tagInfo;
972 }
973 }
974 } else {
975 # get hash of new tags to edit/create in this directory
976 372 $newTags = $et->GetNewTagInfoHash($tagTablePtr);
977 # make lookup of language tags for each ID
978 372 foreach (keys %$newTags) {
979 42 ▶ next unless $$newTags{$_}{LangCode} and $$newTags{$_}{SrcTagInfo};
Branch: 1 branch
BranchTrueFalseTotal
unless $newTags->{$_}{"LangCode"} and $newTags->{$_}{"SrcTagInfo"} 36 6 42
Condition66%2/3
$newTags->{$_}{"LangCode"} and $newTags->{$_}{"SrcTagInfo"}
!ll&&!rl&&r
3606
MC/DC50%1/2
$newTags->{$_}{"LangCode"} and $newTags->{$_}{"SrcTagInfo"}
$newTags->{$_}{"LangCode"} $newTags->{$_}{"SrcTagInfo"}
Truth table66%2/3
A and B
A= $newTags->{$_}{"LangCode"}B= $newTags->{$_}{"SrcTagInfo"}
ABresult
0X0
100
111
980 6 my $id = $$newTags{$_}{SrcTagInfo}{TagID};
981 6 ▶ $langTags{$id} = { } unless $langTags{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless $langTags{$id} 6 0 6
982 6 $langTags{$id}{$_} = $$newTags{$_};
983 }
984 }
985 412 ▶ if ($curPath eq $writePath or $createKeys) {
Branch: 1 branch
BranchTrueFalseTotal
if ($curPath eq $writePath or $createKeys) 166 246 412
Condition100%3/3
$curPath eq $writePath or $createKeys
l!l&&r!l&&!r
13630246
MC/DC100%2/2
$curPath eq $writePath or $createKeys
$curPath eq $writePath $createKeys
Truth table100%3/3
A or B
A= $curPath eq $writePathB= $createKeys
ABresult
1X1
011
000
986 166 $canCreate = 1;
987 # (must check the appropriate Keys delete flag if this is a Keys ItemList)
988 166 ▶ $delGrp = $$et{DEL_GROUP}{$createKeys ? $keysGrp : $dirName};
Branch: 1 branch
BranchTrueFalseTotal
$createKeys ? : 40 126 166
989 }
990 412 ▶ $atomCount = $$tagTablePtr{VARS}{ATOM_COUNT} if $$tagTablePtr{VARS};
Branch: 1 branch
BranchTrueFalseTotal
if $tagTablePtr->{"VARS"} 3 409 412
991  
992 412 $tag = $lastTag = '';
993 412 ▶ $itemIndex = 0 if $dirName eq 'ItemPropertyContainer';
Branch: 1 branch
BranchTrueFalseTotal
if $dirName eq "ItemPropertyContainer" 3 409 412
994  
995 # read ahead to parse item property associations if this is 'iprp' ItemProperties
996 # (necessary to determine which properties belong to primary item in HEIC file)
997 412 ▶ if ($dirName eq 'ItemProperties') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirName eq "ItemProperties") 3 409 412
998 3 my $pos = $raf->Tell();
999 3 for (;;) {
1000 6 ▶ $raf->Read($buf2, 8) == 8 or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buf2, 8) == 8 or last 6 0 6
1001 6 my $size = Get32u(\$buf2, 0) - 8; # (atom size without 8-byte header)
1002 6 $tag = substr($buf2, 4, 4);
1003 6 ▶ last if $size < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $size < 0 0 6 6
1004 6 ▶ $tag eq 'ipma' or $raf->Seek($size, 1), next;
Branch: 1 branch
BranchTrueFalseTotal
$tag eq "ipma" or $raf->Seek($size, 1), next 3 3 6
1005 3 ▶ ParseItemPropAssoc($buf2,$et) if $raf->Read($buf2,$size) == $size;
Branch: 1 branch
BranchTrueFalseTotal
if $raf->Read($buf2, $size) == $size 3 0 3
1006 3 last;
1007 }
1008 3 $raf->Seek($pos);
1009 }
1010 412 for (;;) { # loop through all atoms at this level
1011 1802 ▶ ++$itemIndex if defined $itemIndex;
Branch: 1 branch
BranchTrueFalseTotal
if defined $itemIndex 15 1787 1802
1012 1802 $lastPos = $raf->Tell();
1013 # stop processing if we reached a known trailer
1014 1802 ▶ if ($trailer and $lastPos >= $$trailer[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trailer and $lastPos >= $trailer->[1]) 0 1802 1802
Condition33%1/3
$trailer and $lastPos >= $trailer->[1]
!ll&&!rl&&r
180200
MC/DC0%0/2
$trailer and $lastPos >= $trailer->[1]
$trailer $lastPos >= $trailer->[1]
Truth table33%1/3
A and B
A= $trailerB= $lastPos >= $trailer->[1]
ABresult
0X0
100
111
1015 0 ▶ $errStr = "Corrupted $$trailer[0] trailer" if $lastPos != $$trailer[1];
Branch: 1 branch
BranchTrueFalseTotal
if $lastPos != $trailer->[1] 0 0 0
1016 0 last;
1017 }
1018 1802 ▶ $lastTag = $tag if $$tagTablePtr{$tag}; # keep track of last known tag
Branch: 1 branch
BranchTrueFalseTotal
if $tagTablePtr->{$tag} 1327 475 1802
1019 1802 ▶ if (defined $atomCount and --$atomCount < 0 and $dataPt) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $atomCount and --$atomCount < 0 and $dataPt) 0 1802 1802
Condition33%2/6
defined $atomCount and --$atomCount < 0 and $dataPt
!ll&&!rl&&r
180200
defined $atomCount and --$atomCount < 0
!ll&&!rl&&r
180200
MC/DC0%0/3
defined $atomCount and --$atomCount < 0 and $dataPt
defined $atomCount --$atomCount < 0 $dataPt
Truth table25%1/4
A and B and C
A= defined $atomCountB= --$atomCount < 0C= $dataPt
ABCresult
0XX0
10X0
1100
1111
1020 # stop processing now and just copy the rest of the atom
1021 0 ▶ Write($outfile, substr($$dataPt, $raf->Tell())) or $rtnVal=$rtnErr, $err=1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, substr($$dataPt, $raf->Tell)) or $rtnVal = $rtnErr, $err = 1 0 0 0
1022 0 last;
1023 }
1024 1802 my ($hdr, $buff, $keysIndex);
1025 1802 my $n = $raf->Read($hdr, 8);
1026 1802 ▶ unless ($n == 8) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($n == 8) 412 1390 1802
1027 412 ▶ if ($n == 4 and $hdr eq "\0\0\0\0") {
Branch: 2 branches
BranchTrueFalseTotal
if ($n == 4 and $hdr eq "\000\000\000\000") { } 0 412 412
elsif ($n != 0) { } 0 412 412
Condition33%1/3
$n == 4 and $hdr eq "\0\0\0\0"
!ll&&!rl&&r
41200
MC/DC0%0/2
$n == 4 and $hdr eq "\0\0\0\0"
$n == 4 $hdr eq "\0\0\0\0"
Truth table33%1/3
A and B
A= $n == 4B= $hdr eq "\0\0\0\0"
ABresult
0X0
100
111
1028 # "for historical reasons" the udta is optionally terminated by 4 zeros (ref 1)
1029 # --> hold this terminator to the end
1030 0 $term = $hdr;
1031 } elsif ($n != 0) {
1032 # warn unless this is 1-3 pad bytes
1033 0 ▶ $et->Error("Unknown $n bytes at end of file", 1) if $n > 3 or $hdr ne "\0" x $n;
Branch: 1 branch
BranchTrueFalseTotal
if $n > 3 or $hdr ne "\0" x $n 0 0 0
Condition0%0/3
$n > 3 or $hdr ne "\0" x $n
l!l&&r!l&&!r
000
MC/DC0%0/2
$n > 3 or $hdr ne "\0" x $n
$n > 3 $hdr ne "\0" x $n
Truth table0%0/3
A or B
A= $n > 3B= $hdr ne "\0" x $n
ABresult
1X1
011
000
1034 }
1035 412 last;
1036 }
1037 1390 my $size = Get32u(\$hdr, 0) - 8; # (atom size without 8-byte header)
1038 1390 $tag = substr($hdr, 4, 4);
1039 1390 ▶ if ($size == -7) {
Branch: 3 branches
BranchTrueFalseTotal
if ($size == -7) { } 3 1387 1390
elsif ($size == -8) { } 0 1387 1387
elsif ($size < 0) { } 0 1387 1387
1040 # read the extended size
1041 3 ▶ $raf->Read($buff, 8) == 8 or $errStr = 'Truncated extended atom', last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, 8) == 8 or $errStr = "Truncated extended atom", last 3 0 3
1042 3 $hdr .= $buff;
1043 3 my ($hi, $lo) = unpack('NN', $buff);
1044 3 ▶ if ($hi or $lo > 0x7fffffff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hi or $lo > 2147483647) 0 3 3
Condition33%1/3
$hi or $lo > 2147483647
l!l&&r!l&&!r
003
MC/DC0%0/2
$hi or $lo > 2147483647
$hi $lo > 2147483647
Truth table33%1/3
A or B
A= $hiB= $lo > 2147483647
ABresult
1X1
011
000
1045 0 ▶ if ($hi > 0x7fffffff) {
Branch: 3 branches
BranchTrueFalseTotal
if ($hi > 2147483647) { } 0 0 0
elsif (not $et->Options('LargeFileSupport')) { } 0 0 0
elsif ($et->Options('LargeFileSupport') eq '2') { } 0 0 0
1046 0 $errStr = 'Invalid atom size';
1047 0 last;
1048 } elsif (not $et->Options('LargeFileSupport')) {
1049 0 $et->Error('End of processing at large atom (LargeFileSupport not enabled)');
1050 0 last;
1051 } elsif ($et->Options('LargeFileSupport') eq '2') {
1052 0 $et->Warn('Processing large atom (LargeFileSupport is 2)');
1053 }
1054 }
1055 3 $size = $hi * 4294967296 + $lo - 16;
1056 3 ▶ $size < 0 and $errStr = 'Invalid extended atom size', last;
Branch: 1 branch
BranchTrueFalseTotal
$size < 0 and $errStr = "Invalid extended atom size", last 0 3 3
1057 } elsif ($size == -8) {
1058 0 ▶ if ($dataPt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dataPt) { } 0 0 0
1059 0 ▶ last if $$dirInfo{DirName} eq 'CanonCNTH'; # (this is normal for Canon CNTH atom)
Branch: 1 branch
BranchTrueFalseTotal
if $dirInfo->{"DirName"} eq "CanonCNTH" 0 0 0
1060 0 my $pos = $raf->Tell() - 4;
1061 0 $raf->Seek(0,2);
1062 0 my $str = $$dirInfo{DirName} . ' with ' . ($raf->Tell() - $pos) . ' bytes';
1063 0 $et->Error("Terminator found in $str remaining", 1);
1064 } else {
1065 # size of zero is only valid for top-level atom, and
1066 # indicates the atom extends to the end of file
1067 # (save in mdat list to write later; with zero end position to copy rest of file)
1068 0 push @mdat, [ $raf->Tell(), 0, $hdr ];
1069 }
1070 0 last;
1071 } elsif ($size < 0) {
1072 0 $errStr = 'Invalid atom size';
1073 0 last;
1074 }
1075  
1076 # keep track of 'mdat' atom locations for writing later
1077 1390 ▶ if ($tag eq 'mdat') {
Branch: 3 branches
BranchTrueFalseTotal
if ($tag eq 'mdat') { } 26 1364 1390
elsif ($tag eq 'cmov') { } 0 1364 1364
elsif ($tag eq 'wide') { } 0 1364 1364
1078 26 ▶ if ($dataPt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dataPt) 0 26 26
1079 0 $et->Error("'mdat' not at top level");
1080 0 last;
1081 }
1082 26 push @mdat, [ $raf->Tell(), $raf->Tell() + $size, $hdr ];
1083 26 ▶ $raf->Seek($size, 1) or $et->Error("Seek error in mdat atom"), return $rtnVal;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($size, 1) or $et->Error("Seek error in mdat atom"), (return $rtnVal) 26 0 26
1084 26 next;
1085 } elsif ($tag eq 'cmov') {
1086 0 $et->Error("Can't yet write compressed movie metadata");
1087 0 return $rtnVal;
1088 } elsif ($tag eq 'wide') {
1089 0 ▶ if ($size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size) 0 0 0
1090 0 $et->Warn("Incorrect size for 'wide' atom ($size bytes)");
1091 0 ▶ $raf->Seek($size, 1) or $et->Error('Truncated wide atom');
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($size, 1) or $et->Error("Truncated wide atom") 0 0 0
1092 }
1093 0 next; # drop 'wide' tag
1094 }
1095  
1096 # read the atom data
1097 1364 my $got;
1098 1364 ▶ if (not $size) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $size) { } 7 1357 1364
1099 7 $buff = '';
1100 7 $got = 0;
1101 } else {
1102 # read the atom data (but only first 64kB if data is huge)
1103 1357 ▶ $got = $raf->Read($buff, $size > $maxReadLen ? 0x10000 : $size);
Branch: 1 branch
BranchTrueFalseTotal
$size > $maxReadLen ? : 0 1357 1357
1104 }
1105 1364 ▶ if ($got != $size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got != $size) 0 1364 1364
1106 # ignore up to 256 bytes of garbage at end of file
1107 0 my $type;
1108 0 ▶ if ($got <= 256 and $size >= 1024 and $tag ne 'mdat' or
Branch: 1 branch
BranchTrueFalseTotal
if ($got <= 256 and $size >= 1024 and $tag ne 'mdat' or $got < 3000 and pack('N', $size) =~ /^<b[r>]/ and $type = 'extraneous HTML') { } 0 0 0
Condition0%0/14
$got <= 256 and $size >= 1024 and $tag ne "mdat" or $got < 3000 and pack("N", $size) =~ /^<b[r>]/ and $type = "extraneous HTML"
l!l&&r!l&&!r
000
$got <= 256 and $size >= 1024 and $tag ne "mdat"
!ll&&!rl&&r
000
$got <= 256 and $size >= 1024
!ll&&!rl&&r
000
$got < 3000 and pack("N", $size) =~ /^<b[r>]/ and $type = "extraneous HTML"
!ll
00
$got < 3000 and pack("N", $size) =~ /^<b[r>]/
!ll&&!rl&&r
000
MC/DC0%0/5
$got <= 256 and $size >= 1024 and $tag ne "mdat" or $got < 3000 and pack("N", $size) =~ /^<b[r>]/ and $type = "extraneous HTML"
$got <= 256 $size >= 1024 $tag ne "mdat" $got < 3000 pack("N", $size) =~ /^<b[r>]/
Truth table0%0/10
A and B and C or D and E
A= $got <= 256B= $size >= 1024C= $tag ne "mdat"D= $got < 3000E= pack("N", $size) =~ /^<b[r>]/
ABCDEresult
111XX1
0XX111
10X111
110111
0XX0X0
0XX100
10X0X0
10X100
1100X0
110100
1109 $got < 3000 and pack('N',$size) =~ /^<b[r>]/ and $type = 'extraneous HTML')
1110 {
1111 0 my $bytes = $got + length $hdr;
1112 0 ▶ $type or $type = 'garbage';
Branch: 1 branch
BranchTrueFalseTotal
$type or $type = "garbage" 0 0 0
1113 0 ▶ if ($$et{OPTIONS}{IgnoreMinorErrors}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{'OPTIONS'}{'IgnoreMinorErrors'}) { } 0 0 0
1114 0 $et->Warn("Deleted $type at end of file ($bytes bytes)");
1115 0 $buff = $hdr = '';
1116 } else {
1117 0 $et->Error("Possible $type at end of file ($bytes bytes)", 1);
1118 0 return $rtnVal;
1119 }
1120 } else {
1121 0 $tag = PrintableTagID($tag,3);
1122 0 ▶ if ($size > $maxReadLen and $got == 0x10000) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size > $maxReadLen and $got == 65536) { } 0 0 0
Condition0%0/3
$size > $maxReadLen and $got == 65536
!ll&&!rl&&r
000
MC/DC0%0/2
$size > $maxReadLen and $got == 65536
$size > $maxReadLen $got == 65536
Truth table0%0/3
A and B
A= $size > $maxReadLenB= $got == 65536
ABresult
0X0
100
111
1123 0 my $mb = int($size / 0x100000 + 0.5);
1124 0 $errStr = "'${tag}' atom is too large for rewriting ($mb MB)";
1125 } else {
1126 0 $errStr = "Truncated '${tag}' atom";
1127 }
1128 0 last;
1129 }
1130 }
1131 # save the handler type of the track media
1132 1364 ▶ if ($tag eq 'hdlr' and length $buff >= 12 and
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq "hdlr" and length $buff >= 12 and @{$et->{"PATH"};} and $et->{"PATH"}[-1] eq "Media") 43 1321 1364
Condition77%7/9
$tag eq "hdlr" and length $buff >= 12 and @{$et->{"PATH"};} and $et->{"PATH"}[-1] eq "Media"
!ll&&!rl&&r
12536843
$tag eq "hdlr" and length $buff >= 12 and @{$et->{"PATH"};}
!ll&&!rl&&r
12530111
$tag eq "hdlr" and length $buff >= 12
!ll&&!rl&&r
12530111
MC/DC50%2/4
$tag eq "hdlr" and length $buff >= 12 and @{$et->{"PATH"};} and $et->{"PATH"}[-1] eq "Media"
$tag eq "hdlr" length $buff >= 12 @{$et->{"PATH"};} $et->{"PATH"}[-1] eq "Media"
Truth table60%3/5
A and B and C and D
A= $tag eq "hdlr"B= length $buff >= 12C= @{$et->{"PATH"};}D= $et->{"PATH"}[-1] eq "Media"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1133 111 @{$$et{PATH}} and $$et{PATH}[-1] eq 'Media')
1134 {
1135 43 $$et{MediaType} = substr($buff,8,4);
1136 }
1137 # if this atom stores offsets, save its location so we can fix up offsets later
1138 # (are there any other atoms that may store absolute file offsets?)
1139 1364 ▶ if ($tag =~ /^(stco|co64|iloc|mfra|moof|sidx|saio|gps |CTBO|uuid)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ /^(stco|co64|iloc|mfra|moof|sidx|saio|gps |CTBO|uuid)$/) 59 1305 1364
1140 # (note that we only need to do this if the media data is stored in this file)
1141 59 my $flg = $$et{QtDataFlg};
1142 59 ▶ if ($tag eq 'mfra' or $tag eq 'moof') {
Branch: 7 branches
BranchTrueFalseTotal
if ($tag eq 'mfra' or $tag eq 'moof') { } 0 59 59
elsif ($tag eq 'sidx' or $tag eq 'saio') { } 0 59 59
elsif ($tag eq 'iloc') { } 3 56 59
elsif ($tag eq 'gps ') { } 0 56 56
elsif ($tag eq 'CTBO' or $tag eq 'uuid') { } 13 43 56
elsif (not $flg or $flg == 1) { } 43 0 43
elsif ($flg == 3) { } 0 0 0
Condition33%1/3
$tag eq "mfra" or $tag eq "moof"
l!l&&r!l&&!r
0059
MC/DC0%0/2
$tag eq "mfra" or $tag eq "moof"
$tag eq "mfra" $tag eq "moof"
Truth table33%1/3
A or B
A= $tag eq "mfra"B= $tag eq "moof"
ABresult
1X1
011
000
1143 0 $et->Error("Can't yet handle movie fragments when writing");
1144 0 return $rtnVal;
1145 ▶ } elsif ($tag eq 'sidx' or $tag eq 'saio') {
Condition33%1/3
$tag eq "sidx" or $tag eq "saio"
l!l&&r!l&&!r
0059
MC/DC0%0/2
$tag eq "sidx" or $tag eq "saio"
$tag eq "sidx" $tag eq "saio"
Truth table33%1/3
A or B
A= $tag eq "sidx"B= $tag eq "saio"
ABresult
1X1
011
000
1146 0 $et->Error("Can't yet handle $tag box when writing");
1147 0 return $rtnVal;
1148 } elsif ($tag eq 'iloc') {
1149 3 ▶ Handle_iloc($et, $dirInfo, \$buff, $outfile) or $et->Error('Error parsing iloc atom');
Branch: 1 branch
BranchTrueFalseTotal
&Handle_iloc($et, $dirInfo, \$buff, $outfile) or $et->Error("Error parsing iloc atom") 3 0 3
1150 } elsif ($tag eq 'gps ') {
1151 # (only care about the 'gps ' box in 'moov')
1152 0 ▶ if ($$dirInfo{DirID} and $$dirInfo{DirID} eq 'moov' and length $buff > 8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirInfo->{"DirID"} and $dirInfo->{"DirID"} eq "moov" and length $buff > 8) 0 0 0
Condition0%0/6
$dirInfo->{"DirID"} and $dirInfo->{"DirID"} eq "moov" and length $buff > 8
!ll&&!rl&&r
000
$dirInfo->{"DirID"} and $dirInfo->{"DirID"} eq "moov"
!ll&&!rl&&r
000
MC/DC0%0/3
$dirInfo->{"DirID"} and $dirInfo->{"DirID"} eq "moov" and length $buff > 8
$dirInfo->{"DirID"} $dirInfo->{"DirID"} eq "moov" length $buff > 8
Truth table0%0/4
A and B and C
A= $dirInfo->{"DirID"}B= $dirInfo->{"DirID"} eq "moov"C= length $buff > 8
ABCresult
0XX0
10X0
1100
1111
1153 0 my $off = $$dirInfo{ChunkOffset};
1154 0 my $num = Get32u(\$buff, 4);
1155 0 ▶ $num = int((length($buff) - 8) / 8) if $num * 8 + 8 > length($buff);
Branch: 1 branch
BranchTrueFalseTotal
if $num * 8 + 8 > length $buff 0 0 0
1156 0 my $i;
1157 0 ▶ for ($i=0; $i<$num; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $num) 0 0 0
1158 0 push @$off, [ 'stco_gps ', length($$outfile) + length($hdr) + 8 + $i * 8, 4 ];
1159 }
1160 }
1161 ▶ } elsif ($tag eq 'CTBO' or $tag eq 'uuid') { # hack for updating CR3 CTBO offsets
Condition100%3/3
$tag eq "CTBO" or $tag eq "uuid"
l!l&&r!l&&!r
31043
MC/DC100%2/2
$tag eq "CTBO" or $tag eq "uuid"
$tag eq "CTBO" $tag eq "uuid"
Truth table100%3/3
A or B
A= $tag eq "CTBO"B= $tag eq "uuid"
ABresult
1X1
011
000
1162 13 push @{$$dirInfo{ChunkOffset}}, [ $tag, length($$outfile), length($hdr) + $size ];
1163 ▶ } elsif (not $flg or $flg == 1) {
Condition33%1/3
not $flg or $flg == 1
l!l&&r!l&&!r
0430
MC/DC0%0/2
not $flg or $flg == 1
not $flg $flg == 1
Truth table33%1/3
not(A) or B
A= not $flgB= $flg == 1
ABresult
1X1
011
000
1164 # assume "1" if stsd is yet to be read
1165 43 ▶ $flg or $$et{AssumedDataRef} = 1;
Branch: 1 branch
BranchTrueFalseTotal
$flg or $et->{"AssumedDataRef"} = 1 43 0 43
1166 # must update offsets since the data is in this file
1167 43 push @{$$dirInfo{ChunkOffset}}, [ $tag, length($$outfile) + length($hdr), $size ];
1168 } elsif ($flg == 3) {
1169 0 $et->Error("Can't write files with mixed internal/external media data");
1170 0 return $rtnVal;
1171 }
1172 }
1173  
1174 # rewrite this atom
1175 1364 my $tagInfo = $et->GetTagInfo($tagTablePtr, $tag, \$buff);
1176  
1177 # call write hook if it exists
1178 1364 ▶ &{$$tagInfo{WriteHook}}($buff,$et) if $tagInfo and $$tagInfo{WriteHook};
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo and $tagInfo->{"WriteHook"} 18 1346 1364
Condition100%3/3
$tagInfo and $tagInfo->{"WriteHook"}
!ll&&!rl&&r
110123618
MC/DC100%2/2
$tagInfo and $tagInfo->{"WriteHook"}
$tagInfo $tagInfo->{"WriteHook"}
Truth table100%3/3
A and B
A= $tagInfoB= $tagInfo->{"WriteHook"}
ABresult
0X0
100
111
1179  
1180 # allow numerical tag ID's (ItemList entries defined by Keys)
1181 1364 ▶ if (not $tagInfo and $dirName eq 'ItemList' and $$et{$keysGrp}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $tagInfo and $dirName eq "ItemList" and $et->{$keysGrp}) 36 1328 1364
Condition83%5/6
not $tagInfo and $dirName eq "ItemList" and $et->{$keysGrp}
!ll&&!rl&&r
1328036
not $tagInfo and $dirName eq "ItemList"
!ll&&!rl&&r
12547436
MC/DC66%2/3
not $tagInfo and $dirName eq "ItemList" and $et->{$keysGrp}
not $tagInfo $dirName eq "ItemList" $et->{$keysGrp}
Truth table75%3/4
not(A) and B and C
A= not $tagInfoB= $dirName eq "ItemList"C= $et->{$keysGrp}
ABCresult
0XX0
10X0
1100
1111
1182 36 $keysIndex = unpack('N', $tag);
1183 36 my $newIndex = $$et{$keysGrp}{Remap}{$keysIndex};
1184 36 ▶ if (defined $newIndex) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newIndex) { } 36 0 36
1185 36 $tagInfo = $$et{$keysGrp}{Info}{$keysIndex};
1186 36 ▶ unless ($newIndex) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($newIndex) 12 24 36
1187 12 ▶ if ($tagInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo) { } 1 11 12
1188 1 $et->VPrint(1," - Keys:$$tagInfo{Name}");
1189 } else {
1190 11 ▶ $delCount = ($delCount || 0) + 1;
Condition100%2/2
$delCount || 0
l!l
65
MC/DC100%1/1
$delCount || 0
$delCount
Truth table100%2/2
A
A= $delCount
Aresult
11
00
1191 }
1192 12 ++$$et{CHANGED};
1193 12 next;
1194 }
1195 # use the new Keys index of this item if it changed
1196 24 ▶ unless ($keysIndex == $newIndex) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($keysIndex == $newIndex) 2 22 24
1197 2 $tag = Set32u($newIndex);
1198 2 substr($hdr, 4, 4) = $tag;
1199 }
1200 } else {
1201 0 undef $keysIndex;
1202 }
1203 }
1204 # delete all ItemList tags when deleting group, but take care not to delete UserData Meta
1205 1352 ▶ if ($delGrp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delGrp) 123 1229 1352
1206 123 ▶ if ($dirName eq 'ItemList') {
Branch: 2 branches
BranchTrueFalseTotal
if ($dirName eq 'ItemList') { } 70 53 123
elsif ($dirName eq 'UserData' and not $tagInfo && $tagInfo->{'SubDirectory'}) { } 21 54 75
1207 70 ▶ $delCount = ($delCount || 0) + 1;
Condition100%2/2
$delCount || 0
l!l
655
MC/DC100%1/1
$delCount || 0
$delCount
Truth table100%2/2
A
A= $delCount
Aresult
11
00
1208 70 ++$$et{CHANGED};
1209 70 next;
1210 ▶ } elsif ($dirName eq 'UserData' and (not $tagInfo or not $$tagInfo{SubDirectory})) {
Condition83%5/6
$dirName eq "UserData" and not $tagInfo && $tagInfo->{"SubDirectory"}
!ll&&!rl&&r
221021
$tagInfo && $tagInfo->{'SubDirectory'}
!ll&&!rl&&r
02110
MC/DC66%2/3
$dirName eq "UserData" and not $tagInfo && $tagInfo->{"SubDirectory"}
$dirName eq "UserData" $tagInfo $tagInfo->{'SubDirectory'}
Truth table75%3/4
A and not(B && C)
A= $dirName eq "UserData"B= $tagInfoC= $tagInfo->{'SubDirectory'}
ABCresult
0XX0
1110
10X1
1101
1211 21 ▶ $delCount = ($delCount || 0) + 1;
Condition100%2/2
$delCount || 0
l!l
183
MC/DC100%1/1
$delCount || 0
$delCount
Truth table100%2/2
A
A= $delCount
Aresult
11
00
1212 21 ++$$et{CHANGED};
1213 21 next;
1214 }
1215 }
1216 1261 ▶ undef $tagInfo if $tagInfo and $$tagInfo{AddedUnknown};
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo and $tagInfo->{"AddedUnknown"} 0 1261 1261
Condition66%2/3
$tagInfo and $tagInfo->{"AddedUnknown"}
!ll&&!rl&&r
7411870
MC/DC0%0/2
$tagInfo and $tagInfo->{"AddedUnknown"}
$tagInfo $tagInfo->{"AddedUnknown"}
Truth table66%2/3
A and B
A= $tagInfoB= $tagInfo->{"AddedUnknown"}
ABresult
0X0
100
111
1217  
1218 # don't write this tag unless associated with the primary item
1219 # (Note: This relies on iinf and dimg coming before iprp)
1220 1261 ▶ if (defined $itemIndex and $$et{ItemInfo}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $itemIndex and $et->{"ItemInfo"}) 12 1249 1261
Condition66%2/3
defined $itemIndex and $et->{"ItemInfo"}
!ll&&!rl&&r
1249012
MC/DC50%1/2
defined $itemIndex and $et->{"ItemInfo"}
defined $itemIndex $et->{"ItemInfo"}
Truth table66%2/3
A and B
A= defined $itemIndexB= $et->{"ItemInfo"}
ABresult
0X0
100
111
1221 12 my $items = $$et{ItemInfo};
1222 12 my ($id, $prop, $isPrimary);
1223 12 my $primary = $$et{PrimaryItem};
1224 12 ▶ unless (defined $primary) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $primary) 0 12 12
1225 0 ▶ ($primary) = sort { $a <=> $b } keys %{$$et{ItemInfo}} if $$et{ItemInfo};
Branch: 1 branch
BranchTrueFalseTotal
if $et->{"ItemInfo"} 0 0 0
1226 0 ▶ $primary = 0 unless defined $primary;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $primary 0 0 0
1227 }
1228 12 ▶ my $pitem = $$items{$primary} || { };
Condition50%1/2
$items->{$primary} || {}
l!l
120
MC/DC0%0/1
$items->{$primary} || {}
$items->{$primary}
Truth table50%1/2
A
A= $items->{$primary}
Aresult
11
00
1229 12 ▶ $$pitem{RefersTo} or $$pitem{RefersTo} = { };
Branch: 1 branch
BranchTrueFalseTotal
$pitem->{"RefersTo"} or $pitem->{"RefersTo"} = {} 9 3 12
1230 12 ItemID2: foreach $id (reverse sort { $a <=> $b } keys %$items) {
1231 36 ▶ next unless $$items{$id}{Association};
Branch: 1 branch
BranchTrueFalseTotal
unless $items->{$id}{"Association"} 12 24 36
1232 24 my $item = $$items{$id};
1233 24 foreach $prop (@{$$item{Association}}) {
1234 42 ▶ next unless $prop == $itemIndex;
Branch: 1 branch
BranchTrueFalseTotal
unless $prop == $itemIndex 30 12 42
1235 12 ▶ my $dont = $dontInherit{$tag} || 0;
Condition50%1/2
$Image::ExifTool::QuickTime::dontInherit{$tag} || 0
l!l
120
MC/DC0%0/1
$Image::ExifTool::QuickTime::dontInherit{$tag} || 0
$Image::ExifTool::QuickTime::dontInherit{$tag}
Truth table50%1/2
A
A= $Image::ExifTool::QuickTime::dontInherit{$tag}
Aresult
11
00
1236 last unless $id == $primary or (not $dont and
1237 ($$item{RefersTo} and $$item{RefersTo}{$primary})) or
1238 # special case to assume this property belongs to the primary
1239 # image if it belongs to an item referred to by the primary
1240 12 ▶ ($dont != 1 and $$pitem{RefersTo}{$id});
Branch: 1 branch
BranchTrueFalseTotal
unless $id == $primary or not $dont and ($item->{"RefersTo"} and $item->{"RefersTo"}{$primary}) or $dont != 1 and $pitem->{"RefersTo"}{$id} 6 6 12
Condition46%7/15
$id == $primary or not $dont and ($item->{"RefersTo"} and $item->{"RefersTo"}{$primary}) or $dont != 1 and $pitem->{"RefersTo"}{$id}
l!l&&r!l&&!r
606
$id == $primary or not $dont and ($item->{"RefersTo"} and $item->{"RefersTo"}{$primary})
l!l&&r!l&&!r
606
not $dont and ($item->{"RefersTo"} and $item->{"RefersTo"}{$primary})
!ll&&!rl&&r
600
$item->{"RefersTo"} and $item->{"RefersTo"}{$primary}
!ll&&!rl&&r
000
$dont != 1 and $pitem->{"RefersTo"}{$id}
!ll&&!rl&&r
330
MC/DC16%1/6
$id == $primary or not $dont and ($item->{"RefersTo"} and $item->{"RefersTo"}{$primary}) or $dont != 1 and $pitem->{"RefersTo"}{$id}
$id == $primary not $dont $item->{"RefersTo"} $item->{"RefersTo"}{$primary} $dont != 1 $pitem->{"RefersTo"}{$id}
Truth table27%3/11
A or not(B) and C and D or E and F
A= $id == $primaryB= not $dontC= $item->{"RefersTo"}D= $item->{"RefersTo"}{$primary}E= $dont != 1F= $pitem->{"RefersTo"}{$id}
ABCDEFresult
1XXXXX1
0111XX1
00XX111
010X111
0110111
00XX0X0
00XX100
010X0X0
010X100
01100X0
0110100
1241 6 $isPrimary = 1;
1242 6 last ItemID2;
1243 }
1244 }
1245 12 ▶ undef $tagInfo unless $isPrimary;
Branch: 1 branch
BranchTrueFalseTotal
unless $isPrimary 6 6 12
1246 }
1247  
1248 1261 ▶ if ($tagInfo and (not defined $$tagInfo{Writable} or $$tagInfo{Writable})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo and !defined($tagInfo->{"Writable"}) || $tagInfo->{"Writable"}) 1181 80 1261
Condition66%4/6
$tagInfo and !defined($tagInfo->{"Writable"}) || $tagInfo->{"Writable"}
!ll&&!rl&&r
8001181
not defined $tagInfo->{"Writable"} or $tagInfo->{"Writable"}
l!l&&r!l&&!r
1166150
MC/DC33%1/3
$tagInfo and !defined($tagInfo->{"Writable"}) || $tagInfo->{"Writable"}
$tagInfo not defined $tagInfo->{"Writable"} $tagInfo->{"Writable"}
Truth table75%3/4
A and not(B) or C
A= $tagInfoB= not defined $tagInfo->{"Writable"}C= $tagInfo->{"Writable"}
ABCresult
0XX0
1000
11X1
1011
1249 1181 my $subdir = $$tagInfo{SubDirectory};
1250 1181 my ($newData, @chunkOffset);
1251  
1252 1181 ▶ if ($subdir) { # process atoms in this container from a buffer in memory
Branch: 1 branch
BranchTrueFalseTotal
if ($subdir) { } 761 420 1181
1253  
1254 761 ▶ if ($tag eq 'trak') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq "trak") 43 718 761
1255 43 $$et{MediaType} = ''; # init media type for this track
1256 43 delete $$et{AssumedDataRef};
1257 }
1258 761 ▶ my $subName = $$subdir{DirName} || $$tagInfo{Name};
Condition66%2/3
$subdir->{'DirName'} || $tagInfo->{'Name'}
l!l&&r!l&&!r
2884730
MC/DC0%0/2
$subdir->{'DirName'} || $tagInfo->{'Name'}
$subdir->{'DirName'} $tagInfo->{'Name'}
Truth table66%2/3
A || B
A= $subdir->{'DirName'}B= $tagInfo->{'Name'}
ABresult
1X1
011
000
1259 761 ▶ my $start = $$subdir{Start} || 0;
Condition100%2/2
$subdir->{'Start'} || 0
l!l
76685
MC/DC100%1/1
$subdir->{'Start'} || 0
$subdir->{'Start'}
Truth table100%2/2
A
A= $subdir->{'Start'}
Aresult
11
00
1260 761 ▶ my $base = ($$dirInfo{Base} || 0) + $raf->Tell() - $size;
Condition100%2/2
$dirInfo->{'Base'} || 0
l!l
70160
MC/DC100%1/1
$dirInfo->{'Base'} || 0
$dirInfo->{'Base'}
Truth table100%2/2
A
A= $dirInfo->{'Base'}
Aresult
11
00
1261 761 my $dPos = 0;
1262 761 my $hdrLen = $start;
1263 # handle case where known trailer is the payload of a "DontRead" box (eg. 'inst')
1264 761 ▶ $trailer = $$trailer[3] if $$tagInfo{DontRead} and $trailer and $base == $$trailer[1];
Branch: 1 branch
BranchTrueFalseTotal
if $tagInfo->{"DontRead"} and $trailer and $base == $trailer->[1] 0 761 761
Condition33%2/6
$tagInfo->{"DontRead"} and $trailer and $base == $trailer->[1]
!ll&&!rl&&r
76100
$tagInfo->{"DontRead"} and $trailer
!ll&&!rl&&r
76100
MC/DC0%0/3
$tagInfo->{"DontRead"} and $trailer and $base == $trailer->[1]
$tagInfo->{"DontRead"} $trailer $base == $trailer->[1]
Truth table25%1/4
A and B and C
A= $tagInfo->{"DontRead"}B= $trailerC= $base == $trailer->[1]
ABCresult
0XX0
10X0
1100
1111
1265 761 ▶ if ($$subdir{Base}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subdir->{"Base"}) 0 761 761
1266 0 my $localBase = eval $$subdir{Base};
1267 0 $dPos -= $localBase;
1268 0 $base -= $dPos;
1269 # get length of header before base offset
1270 0 ▶ $hdrLen -= $localBase if $localBase <= $hdrLen;
Branch: 1 branch
BranchTrueFalseTotal
if $localBase <= $hdrLen 0 0 0
1271 }
1272 my %subdirInfo = (
1273 Parent => $dirName,
1274 DirName => $subName,
1275 Name => $$tagInfo{Name},
1276 TagInfo => $tagInfo,
1277 DirID => $tag,
1278 DataPt => \$buff,
1279 DataLen => $size,
1280 DataPos => $dPos,
1281 DirStart => $start,
1282 DirLen => $size - $start,
1283 Base => $base,
1284 HasData => $$subdir{HasData},
1285 Multi => $$subdir{Multi}, # necessary?
1286 OutFile => $outfile,
1287 NoRefTest=> 1, # don't check directory references
1288 WriteGroup => $$tagInfo{WriteGroup},
1289 Permanent => $$tagInfo{Permanent},
1290 # initialize array to hold details about chunk offset table
1291 # (each entry has 3-5 items: 0=atom type, 1=table offset, 2=table size,
1292 # 3=optional base offset, 4=optional item ID)
1293 761 ChunkOffset => \@chunkOffset,
1294 );
1295 # set InPlace flag so XMP will be padded properly when
1296 # QuickTimePad is used if this is an XMP directory
1297 761 ▶ $subdirInfo{InPlace} = 2 if $et->Options('QuickTimePad');
Branch: 1 branch
BranchTrueFalseTotal
if $et->Options("QuickTimePad") 0 761 761
1298 # pass the header pointer if necessary (for EXIF IFD's
1299 # where the Base offset is at the end of the header)
1300 761 ▶ if ($hdrLen and $hdrLen < $size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hdrLen and $hdrLen < $size) 76 685 761
Condition66%2/3
$hdrLen and $hdrLen < $size
!ll&&!rl&&r
685076
MC/DC50%1/2
$hdrLen and $hdrLen < $size
$hdrLen $hdrLen < $size
Truth table66%2/3
A and B
A= $hdrLenB= $hdrLen < $size
ABresult
0X0
100
111
1301 76 my $header = substr($buff,0,$hdrLen);
1302 76 $subdirInfo{HeaderPtr} = \$header;
1303 }
1304 761 ▶ SetByteOrder('II') if $$subdir{ByteOrder} and $$subdir{ByteOrder} =~ /^Little/;
Branch: 1 branch
BranchTrueFalseTotal
if $subdir->{"ByteOrder"} and $subdir->{"ByteOrder"} =~ /^Little/ 11 750 761
Condition66%2/3
$subdir->{"ByteOrder"} and $subdir->{"ByteOrder"} =~ /^Little/
!ll&&!rl&&r
750011
MC/DC50%1/2
$subdir->{"ByteOrder"} and $subdir->{"ByteOrder"} =~ /^Little/
$subdir->{"ByteOrder"} $subdir->{"ByteOrder"} =~ /^Little/
Truth table66%2/3
A and B
A= $subdir->{"ByteOrder"}B= $subdir->{"ByteOrder"} =~ /^Little/
ABresult
0X0
100
111
1305 761 my $oldWriteGroup = $$et{CUR_WRITE_GROUP};
1306 761 ▶ if ($subName eq 'Track') {
Branch: 1 branch
BranchTrueFalseTotal
if ($subName eq "Track") 43 718 761
1307 43 ▶ $track or $track = 0;
Branch: 1 branch
BranchTrueFalseTotal
$track or $track = 0 23 20 43
1308 43 $$et{CUR_WRITE_GROUP} = 'Track' . (++$track);
1309 }
1310 761 my $subTable = GetTagTable($$subdir{TagTable});
1311 # demote non-QuickTime errors to warnings
1312 761 ▶ $$et{DemoteErrors} = 1 unless $$subTable{GROUPS}{0} eq 'QuickTime';
Branch: 1 branch
BranchTrueFalseTotal
unless $subTable->{"GROUPS"}{0} eq "QuickTime" 45 716 761
1313 761 my $oldChanged = $$et{CHANGED};
1314 761 $newData = $et->WriteDirectory(\%subdirInfo, $subTable, $$subdir{WriteProc});
1315 761 ▶ if ($$et{DemoteErrors}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"DemoteErrors"}) 41 720 761
1316 # just copy existing subdirectory if a non-quicktime error occurred
1317 41 ▶ $$et{CHANGED} = $oldChanged if $$et{DemoteErrors} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $et->{"DemoteErrors"} > 1 0 41 41
1318 41 delete $$et{DemoteErrors};
1319 }
1320 761 ▶ if (defined $newData and not length $newData and ($$tagInfo{Permanent} or
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newData and not length $newData and $tagInfo->{"Permanent"} || $tagTablePtr->{"PERMANENT"} && !defined($tagInfo->{"Permanent"})) 0 761 761
Condition58%7/12
defined $newData and not length $newData and $tagInfo->{"Permanent"} || $tagTablePtr->{"PERMANENT"} && !defined($tagInfo->{"Permanent"})
!ll&&!rl&&r
738230
defined $newData and not length $newData
!ll&&!rl&&r
24249623
$tagInfo->{"Permanent"} or $tagTablePtr->{"PERMANENT"} and not defined $tagInfo->{"Permanent"}
l!l&&r!l&&!r
0023
$tagTablePtr->{"PERMANENT"} and not defined $tagInfo->{"Permanent"}
!ll&&!rl&&r
2300
MC/DC0%0/5
defined $newData and not length $newData and $tagInfo->{"Permanent"} || $tagTablePtr->{"PERMANENT"} && !defined($tagInfo->{"Permanent"})
defined $newData not length $newData $tagInfo->{"Permanent"} $tagTablePtr->{"PERMANENT"} not defined $tagInfo->{"Permanent"}
Truth table50%3/6
A and not(B) and C or D and not(E)
A= defined $newDataB= not length $newDataC= $tagInfo->{"Permanent"}D= $tagTablePtr->{"PERMANENT"}E= not defined $tagInfo->{"Permanent"}
ABCDEresult
0XXXX0
10XXX0
1100X0
110100
111XX1
110111
1321 ($$tagTablePtr{PERMANENT} and not defined $$tagInfo{Permanent})))
1322 {
1323 # do nothing if trying to delete tag from a PERMANENT table
1324 0 $$et{CHANGED} = $oldChanged;
1325 0 undef $newData;
1326 }
1327 761 ▶ if ($tag eq 'trak') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq "trak") 43 718 761
1328 43 $$et{MediaType} = ''; # reset media type at end of track
1329 43 ▶ if ($$et{AssumedDataRef}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"AssumedDataRef"}) 0 43 43
1330 0 ▶ my $grp = $$et{CUR_WRITE_GROUP} || $dirName;
Condition0%0/3
$et->{'CUR_WRITE_GROUP'} || $dirName
l!l&&r!l&&!r
000
MC/DC0%0/2
$et->{'CUR_WRITE_GROUP'} || $dirName
$et->{'CUR_WRITE_GROUP'} $dirName
Truth table0%0/3
A || B
A= $et->{'CUR_WRITE_GROUP'}B= $dirName
ABresult
1X1
011
000
1331 0 $et->Error("Can't locate data reference to update offsets for $grp");
1332 0 delete $$et{AssumedDataRef};
1333 }
1334 }
1335 761 $$et{CUR_WRITE_GROUP} = $oldWriteGroup;
1336 761 SetByteOrder('MM');
1337 # add back header if necessary
1338 761 ▶ if ($start and defined $newData and (length $newData or
Branch: 1 branch
BranchTrueFalseTotal
if ($start and defined $newData and length $newData || defined $tagInfo->{"Permanent"} && !$tagInfo->{"Permanent"}) 69 692 761
Condition75%9/12
$start and defined $newData and length $newData || defined $tagInfo->{"Permanent"} && !$tagInfo->{"Permanent"}
!ll&&!rl&&r
690269
$start and defined $newData
!ll&&!rl&&r
685571
length $newData or defined $tagInfo->{"Permanent"} and not $tagInfo->{"Permanent"}
l!l&&r!l&&!r
6902
defined $tagInfo->{"Permanent"} and not $tagInfo->{"Permanent"}
!ll&&!rl&&r
200
MC/DC60%3/5
$start and defined $newData and length $newData || defined $tagInfo->{"Permanent"} && !$tagInfo->{"Permanent"}
$start defined $newData length $newData defined $tagInfo->{"Permanent"} not $tagInfo->{"Permanent"}
Truth table66%4/6
A and B and C or D and not(E)
A= $startB= defined $newDataC= length $newDataD= defined $tagInfo->{"Permanent"}E= not $tagInfo->{"Permanent"}
ABCDEresult
0XXXX0
10XXX0
1100X0
110100
111XX1
110111
1339 (defined $$tagInfo{Permanent} and not $$tagInfo{Permanent})))
1340 {
1341 69 $newData = substr($buff,0,$start) . $newData;
1342 69 $$_[1] += $start foreach @chunkOffset;
1343 }
1344 # the directory exists, so we don't need to add it
1345 761 ▶ if ($curPath eq $writePath and $$addDirs{$subName} and $$addDirs{$subName} eq $dirName) {
Branch: 1 branch
BranchTrueFalseTotal
if ($curPath eq $writePath and $addDirs->{$subName} and $addDirs->{$subName} eq $dirName) 42 719 761
Condition100%6/6
$curPath eq $writePath and $addDirs->{$subName} and $addDirs->{$subName} eq $dirName
!ll&&!rl&&r
716342
$curPath eq $writePath and $addDirs->{$subName}
!ll&&!rl&&r
45925745
MC/DC100%3/3
$curPath eq $writePath and $addDirs->{$subName} and $addDirs->{$subName} eq $dirName
$curPath eq $writePath $addDirs->{$subName} $addDirs->{$subName} eq $dirName
Truth table100%4/4
A and B and C
A= $curPath eq $writePathB= $addDirs->{$subName}C= $addDirs->{$subName} eq $dirName
ABCresult
0XX0
10X0
1100
1111
1346 42 delete $$addDirs{$subName};
1347 }
1348 761 $didDir{$tag} = 1; # (note: keyed by tag ID)
1349  
1350 } else { # modify existing QuickTime tags in various formats
1351  
1352 420 my $nvHash = $et->GetNewValueHash($tagInfo);
1353 420 ▶ if ($nvHash or $langTags{$tag} or $delGrp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nvHash or $langTags{$tag} or $delGrp) 12 408 420
Condition83%5/6
$nvHash or $langTags{$tag} or $delGrp
l!l&&r!l&&!r
120408
$nvHash or $langTags{$tag}
l!l&&r!l&&!r
75408
MC/DC66%2/3
$nvHash or $langTags{$tag} or $delGrp
$nvHash $langTags{$tag} $delGrp
Truth table75%3/4
A or B or C
A= $nvHashB= $langTags{$tag}C= $delGrp
ABCresult
1XX1
01X1
0011
0000
1354 12 my $nvHashNoLang = $nvHash;
1355 12 my ($val, $len, $lang, $type, $flags, $ctry, $charsetQuickTime);
1356 12 my $format = $$tagInfo{Format};
1357 12 ▶ my $hasData = ($$dirInfo{HasData} and $buff =~ /\0...data\0/s);
Condition66%2/3
$dirInfo->{'HasData'} && $buff =~ /\0...data\0/s
!ll&&!rl&&r
408
MC/DC50%1/2
$dirInfo->{'HasData'} && $buff =~ /\0...data\0/s
$dirInfo->{'HasData'} $buff =~ /\0...data\0/s
Truth table66%2/3
A && B
A= $dirInfo->{'HasData'}B= $buff =~ /\0...data\0/s
ABresult
0X0
100
111
1358 12 my $langInfo = $tagInfo;
1359 12 ▶ if ($hasData) {
Branch: 3 branches
BranchTrueFalseTotal
if ($hasData) { } 8 4 12
elsif ($format) { } 0 4 4
elsif ($tag =~ /^\xa9/ || $tagInfo->{'IText'} and $size >= ($tagInfo->{'IText'} || 4)) { } 4 0 4
1360 8 my $pos = 0;
1361 8 for (;;$pos+=$len) {
1362 16 ▶ if ($pos + 16 > $size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos + 16 > $size) 8 8 16
1363 # add any new alternate language tags now
1364 8 ▶ if ($langTags{$tag}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($langTags{$tag}) 4 4 8
1365 4 my $tg;
1366 4 foreach $tg ('', sort keys %{$langTags{$tag}}) {
1367 8 ▶ my $ti = $tg ? $langTags{$tag}{$tg} : $nvHashNoLang;
Branch: 1 branch
BranchTrueFalseTotal
$tg ? : 4 4 8
1368 8 $nvHash = $et->GetNewValueHash($ti);
1369 8 ▶ next unless $nvHash and not $$didTag{$nvHash};
Branch: 1 branch
BranchTrueFalseTotal
unless $nvHash and not $didTag->{$nvHash} 5 3 8
Condition100%3/3
$nvHash and not $didTag->{$nvHash}
!ll&&!rl&&r
413
MC/DC100%2/2
$nvHash and not $didTag->{$nvHash}
$nvHash not $didTag->{$nvHash}
Truth table100%3/3
A and not(B)
A= $nvHashB= not $didTag->{$nvHash}
ABresult
0X0
100
111
1370 3 $$didTag{$nvHash} = 1;
1371 3 ▶ next unless $$nvHash{IsCreating} and $et->IsOverwriting($nvHash);
Branch: 1 branch
BranchTrueFalseTotal
unless $nvHash->{"IsCreating"} and $et->IsOverwriting($nvHash) 2 1 3
Condition66%2/3
$nvHash->{"IsCreating"} and $et->IsOverwriting($nvHash)
!ll&&!rl&&r
201
MC/DC50%1/2
$nvHash->{"IsCreating"} and $et->IsOverwriting($nvHash)
$nvHash->{"IsCreating"} $et->IsOverwriting($nvHash)
Truth table66%2/3
A and B
A= $nvHash->{"IsCreating"}B= $et->IsOverwriting($nvHash)
ABresult
0X0
100
111
1372 1 my $newVal = $et->GetNewValue($nvHash);
1373 1 ▶ next unless defined $newVal;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $newVal 0 1 1
1374 1 my $prVal = $newVal;
1375 1 my $flags = FormatQTValue($et, \$newVal, $tagInfo, $format);
1376 1 ▶ next unless defined $newVal;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $newVal 0 1 1
1377 1 my ($ctry, $lang) = (0, 0);
1378 1 ▶ if ($$ti{LangCode}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ti->{"LangCode"}) 1 0 1
1379 1 ▶ unless ($$ti{LangCode} =~ /^([A-Z]{3})?[-_]?([A-Z]{2})?$/i) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ti->{"LangCode"} =~ /^([A-Z]{3})?[-_]?([A-Z]{2})?$/i) 0 1 1
1380 0 $et->Warn("Invalid language code for $$ti{Name}");
1381 0 next;
1382 }
1383 # pack language and country codes
1384 1 ▶ if ($1 and $1 ne 'und') {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 and $1 ne "und") 1 0 1
Condition33%1/3
$1 and $1 ne "und"
!ll&&!rl&&r
001
MC/DC0%0/2
$1 and $1 ne "und"
$1 $1 ne "und"
Truth table33%1/3
A and B
A= $1B= $1 ne "und"
ABresult
0X0
100
111
1385 1 $lang = ($lang << 5) | ($_ - 0x60) foreach unpack 'C*', lc($1);
1386 }
1387 1 ▶ $ctry = unpack('n', pack('a2',uc($2))) if $2 and $2 ne 'ZZ';
Branch: 1 branch
BranchTrueFalseTotal
if $2 and $2 ne "ZZ" 1 0 1
Condition33%1/3
$2 and $2 ne "ZZ"
!ll&&!rl&&r
001
MC/DC0%0/2
$2 and $2 ne "ZZ"
$2 $2 ne "ZZ"
Truth table33%1/3
A and B
A= $2B= $2 ne "ZZ"
ABresult
0X0
100
111
1388 }
1389 1 ▶ $newData = substr($buff, 0, $pos) unless defined $newData;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $newData 1 0 1
1390 1 $newData .= pack('Na4Nnn',16+length($newVal),'data',$flags,$ctry,$lang).$newVal;
1391 1 my $grp = $et->GetGroup($ti, 1);
1392 1 $et->VerboseValue("+ $grp:$$ti{Name}", $prVal);
1393 1 ++$$et{CHANGED};
1394 }
1395 }
1396 8 last;
1397 }
1398 8 ($len, $type, $flags, $ctry, $lang) = unpack("x${pos}Na4Nnn", $buff);
1399 8 ▶ $lang or $lang = $undLang; # treat both 0 and 'und' as 'und'
Branch: 1 branch
BranchTrueFalseTotal
$lang or $lang = $undLang 2 6 8
1400 8 $langInfo = $tagInfo;
1401 8 my $delTag = $delGrp;
1402 8 my $newVal;
1403 8 my $langCode = GetLangCode($lang, $ctry, 1);
1404 8 for (;;) {
1405 8 $langInfo = GetLangInfo($tagInfo, $langCode);
1406 8 $nvHash = $et->GetNewValueHash($langInfo);
1407 8 ▶ last if $nvHash or not $ctry or $lang ne $undLang or length($langCode)==2;
Branch: 1 branch
BranchTrueFalseTotal
if $nvHash or not $ctry or $lang ne $undLang or length $langCode == 2 8 0 8
Condition44%4/9
$nvHash or not $ctry or $lang ne $undLang or length $langCode == 2
l!l&&r!l&&!r
800
$nvHash or not $ctry or $lang ne $undLang
l!l&&r!l&&!r
800
$nvHash or not $ctry
l!l&&r!l&&!r
260
MC/DC0%0/4
$nvHash or not $ctry or $lang ne $undLang or length $langCode == 2
$nvHash not $ctry $lang ne $undLang length $langCode == 2
Truth table40%2/5
A or not(B) or C or D
A= $nvHashB= not $ctryC= $lang ne $undLangD= length $langCode == 2
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1408 # check to see if tag was written with a 2-char country code only
1409 0 $langCode = lc unpack('a2',pack('n',$ctry));
1410 }
1411 # set flag to delete language tag when writing default
1412 # (except for a default-language Keys entry)
1413 8 ▶ if (not $nvHash and $nvHashNoLang) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $nvHash and $nvHashNoLang) 4 4 8
Condition100%3/3
not $nvHash and $nvHashNoLang
!ll&&!rl&&r
224
MC/DC100%2/2
not $nvHash and $nvHashNoLang
not $nvHash $nvHashNoLang
Truth table100%3/3
not(A) and B
A= not $nvHashB= $nvHashNoLang
ABresult
0X0
100
111
1414 4 ▶ if ($lang eq $undLang and not $ctry and not $$didTag{$nvHashNoLang}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lang eq $undLang and not $ctry and not $didTag->{$nvHashNoLang}) { } 4 0 4
Condition33%2/6
$lang eq $undLang and not $ctry and not $didTag->{$nvHashNoLang}
!ll&&!rl&&r
004
$lang eq $undLang and not $ctry
!ll&&!rl&&r
004
MC/DC0%0/3
$lang eq $undLang and not $ctry and not $didTag->{$nvHashNoLang}
$lang eq $undLang not $ctry not $didTag->{$nvHashNoLang}
Truth table25%1/4
A and not(B) and not(C)
A= $lang eq $undLangB= not $ctryC= not $didTag->{$nvHashNoLang}
ABCresult
0XX0
10X0
1100
1111
1415 4 $nvHash = $nvHashNoLang; # write existing default
1416 } else {
1417 0 $delTag = 1; # delete tag
1418 }
1419 }
1420 8 ▶ last if $pos + $len > $size;
Branch: 1 branch
BranchTrueFalseTotal
if $pos + $len > $size 0 8 8
1421 8 ▶ if ($type eq 'data' and $len >= 16) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'data' and $len >= 16) { } 8 0 8
elsif (defined $newData) { } 0 0 0
Condition33%1/3
$type eq "data" and $len >= 16
!ll&&!rl&&r
008
MC/DC0%0/2
$type eq "data" and $len >= 16
$type eq "data" $len >= 16
Truth table33%1/3
A and B
A= $type eq "data"B= $len >= 16
ABresult
0X0
100
111
1422 8 $pos += 16;
1423 8 $len -= 16;
1424 8 $val = substr($buff, $pos, $len);
1425 # decode value (see QuickTime.pm for an explanation)
1426 8 ▶ if ($stringEncoding{$flags}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Image::ExifTool::QuickTime::stringEncoding{$flags}) { } 8 0 8
1427 8 $val = $et->Decode($val, $stringEncoding{$flags});
1428 8 ▶ $val =~ s/\0$// unless $$tagInfo{Binary};
Branch: 1 branch
BranchTrueFalseTotal
unless $tagInfo->{"Binary"} 8 0 8
1429 8 $flags = 0x01; # write all strings as UTF-8
1430 } else {
1431 0 ▶ if ($format) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format) { } 0 0 0
1432 # update flags for the format we are writing
1433 0 ▶ if ($$tagInfo{Writable} and $qtFormat{$$tagInfo{Writable}}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tagInfo->{'Writable'} and $qtFormat{$tagInfo->{'Writable'}}) { } 0 0 0
elsif ($qtFormat{$format}) { } 0 0 0
Condition0%0/3
$tagInfo->{"Writable"} and $qtFormat{$tagInfo->{"Writable"}}
!ll&&!rl&&r
000
MC/DC0%0/2
$tagInfo->{"Writable"} and $qtFormat{$tagInfo->{"Writable"}}
$tagInfo->{"Writable"} $qtFormat{$tagInfo->{"Writable"}}
Truth table0%0/3
A and B
A= $tagInfo->{"Writable"}B= $qtFormat{$tagInfo->{"Writable"}}
ABresult
0X0
100
111
1434 0 $flags = $qtFormat{$$tagInfo{Writable}};
1435 } elsif ($qtFormat{$format}) {
1436 0 $flags = $qtFormat{$format};
1437 }
1438 } else {
1439 0 $format = QuickTimeFormat($flags, $len);
1440 }
1441 0 ▶ $val = ReadValue(\$val, 0, $format, $$tagInfo{Count}, $len) if $format;
Branch: 1 branch
BranchTrueFalseTotal
if $format 0 0 0
1442 }
1443 8 ▶ if (($nvHash and $et->IsOverwriting($nvHash, $val)) or $delTag) {
Branch: 2 branches
BranchTrueFalseTotal
if ($nvHash and $et->IsOverwriting($nvHash, $val) or $delTag) { } 5 3 8
elsif (defined $newData) { } 0 3 3
Condition83%5/6
$nvHash and $et->IsOverwriting($nvHash, $val) or $delTag
l!l&&r!l&&!r
503
$nvHash and $et->IsOverwriting($nvHash, $val)
!ll&&!rl&&r
215
MC/DC66%2/3
$nvHash and $et->IsOverwriting($nvHash, $val) or $delTag
$nvHash $et->IsOverwriting($nvHash, $val) $delTag
Truth table60%3/5
A and B or C
A= $nvHashB= $et->IsOverwriting($nvHash, $val)C= $delTag
ABCresult
11X1
0X11
1011
0X00
1000
1444 5 ▶ $newVal = $et->GetNewValue($nvHash) if defined $nvHash;
Branch: 1 branch
BranchTrueFalseTotal
if defined $nvHash 5 0 5
1445 5 ▶ if ($delTag or not defined $newVal or $$didTag{$nvHash}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delTag or not defined $newVal or $didTag->{$nvHash}) 2 3 5
Condition66%4/6
$delTag or not defined $newVal or $didTag->{$nvHash}
l!l&&r!l&&!r
203
$delTag or not defined $newVal
l!l&&r!l&&!r
023
MC/DC33%1/3
$delTag or not defined $newVal or $didTag->{$nvHash}
$delTag not defined $newVal $didTag->{$nvHash}
Truth table50%2/4
A or not(B) or C
A= $delTagB= not defined $newValC= $didTag->{$nvHash}
ABCresult
1XX1
01X1
0011
0000
1446 # delete the tag
1447 2 my $grp = $et->GetGroup($langInfo, 1);
1448 2 $et->VerboseValue("- $grp:$$langInfo{Name}", $val);
1449 # copy data up to start of this tag to delete this value
1450 2 ▶ $newData = substr($buff, 0, $pos-16) unless defined $newData;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $newData 2 0 2
1451 2 ++$$et{CHANGED};
1452 2 next;
1453 }
1454 3 my $prVal = $newVal;
1455 # format new value for writing (and get new flags)
1456 3 $flags = FormatQTValue($et, \$newVal, $tagInfo, $format);
1457 3 ▶ next unless defined $newVal;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $newVal 0 3 3
1458 3 my $grp = $et->GetGroup($langInfo, 1);
1459 3 $et->VerboseValue("- $grp:$$langInfo{Name}", $val);
1460 3 $et->VerboseValue("+ $grp:$$langInfo{Name}", $prVal);
1461 3 ▶ $newData = substr($buff, 0, $pos-16) unless defined $newData;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $newData 3 0 3
1462 3 ▶ my $wLang = $lang eq $undLang ? 0 : $lang;
Branch: 1 branch
BranchTrueFalseTotal
$lang eq $undLang ? : 3 0 3
1463 3 $newData .= pack('Na4Nnn', length($newVal)+16, $type, $flags, $ctry, $wLang);
1464 3 $newData .= $newVal;
1465 3 ++$$et{CHANGED};
1466 } elsif (defined $newData) {
1467 0 $newData .= substr($buff, $pos-16, $len+16);
1468 }
1469 } elsif (defined $newData) {
1470 0 $newData .= substr($buff, $pos, $len);
1471 }
1472 6 ▶ $$didTag{$nvHash} = 1 if $nvHash;
Branch: 1 branch
BranchTrueFalseTotal
if $nvHash 4 2 6
1473 }
1474 8 ▶ $newData .= substr($buff, $pos) if defined $newData and $pos < $size;
Branch: 1 branch
BranchTrueFalseTotal
if defined $newData and $pos < $size 0 8 8
Condition66%2/3
defined $newData and $pos < $size
!ll&&!rl&&r
260
MC/DC0%0/2
defined $newData and $pos < $size
defined $newData $pos < $size
Truth table66%2/3
A and B
A= defined $newDataB= $pos < $size
ABresult
0X0
100
111
1475 8 undef $val; # (already constructed $newData)
1476 } elsif ($format) {
1477 0 $val = ReadValue(\$buff, 0, $format, undef, $size);
1478 ▶ } elsif (($tag =~ /^\xa9/ or $$tagInfo{IText}) and $size >= ($$tagInfo{IText} || 4)) {
Condition37%3/8
$tag =~ /^\xa9/ || $tagInfo->{"IText"} and $size >= ($tagInfo->{"IText"} || 4)
!ll&&!rl&&r
004
$tag =~ /^\xa9/ or $tagInfo->{"IText"}
l!l&&r!l&&!r
400
$tagInfo->{'IText'} || 4
l!l
04
MC/DC0%0/3
$tag =~ /^\xa9/ || $tagInfo->{"IText"} and $size >= ($tagInfo->{"IText"} || 4)
$tag =~ /^\xa9/ $tagInfo->{"IText"} $size >= ($tagInfo->{"IText"} || 4)
MC/DC0%0/1
$tagInfo->{'IText'} || 4
$tagInfo->{'IText'}
Truth table20%1/5
A or B and C
A= $tag =~ /^\xa9/B= $tagInfo->{"IText"}C= $size >= ($tagInfo->{"IText"} || 4)
ABCresult
00X0
1X00
0100
1X11
0111
Truth table50%1/2
A
A= $tagInfo->{'IText'}
Aresult
11
00
1479 4 my $hdr;
1480 4 ▶ if ($$tagInfo{IText} and $$tagInfo{IText} >= 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{'IText'} and $tagInfo->{'IText'} >= 6) { } 0 4 4
Condition33%1/3
$tagInfo->{"IText"} and $tagInfo->{"IText"} >= 6
!ll&&!rl&&r
400
MC/DC0%0/2
$tagInfo->{"IText"} and $tagInfo->{"IText"} >= 6
$tagInfo->{"IText"} $tagInfo->{"IText"} >= 6
Truth table33%1/3
A and B
A= $tagInfo->{"IText"}B= $tagInfo->{"IText"} >= 6
ABresult
0X0
100
111
1481 0 my $iText = $$tagInfo{IText};
1482 0 my $pos = $iText - 2;
1483 0 $lang = unpack("x${pos}n", $buff);
1484 0 $hdr = substr($buff,4,$iText-6);
1485 0 $len = $size - $iText;
1486 0 $val = substr($buff, $iText, $len);
1487 } else {
1488 4 ($len, $lang) = unpack('nn', $buff);
1489 4 ▶ $len -= 4 if 4 + $len > $size; # (see QuickTime.pm for explanation)
Branch: 1 branch
BranchTrueFalseTotal
if 4 + $len > $size 0 4 4
1490 4 ▶ $len = $size - 4 if $len > $size - 4 or $len < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $len > $size - 4 or $len < 0 0 4 4
Condition33%1/3
$len > $size - 4 or $len < 0
l!l&&r!l&&!r
004
MC/DC0%0/2
$len > $size - 4 or $len < 0
$len > $size - 4 $len < 0
Truth table33%1/3
A or B
A= $len > $size - 4B= $len < 0
ABresult
1X1
011
000
1491 4 $val = substr($buff, 4, $len);
1492 }
1493 4 ▶ $lang or $lang = $undLang; # treat both 0 and 'und' as 'und'
Branch: 1 branch
BranchTrueFalseTotal
$lang or $lang = $undLang 0 4 4
1494 4 my $enc;
1495 4 ▶ if ($lang < 0x400 and $val !~ /^\xfe\xff/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lang < 1024 and not $val =~ /^\xfe\xff/) { } 0 4 4
Condition33%1/3
$lang < 1024 and not $val =~ /^\xfe\xff/
!ll&&!rl&&r
400
MC/DC0%0/2
$lang < 1024 and not $val =~ /^\xfe\xff/
$lang < 1024 not $val =~ /^\xfe\xff/
Truth table33%1/3
A and not(B)
A= $lang < 1024B= not $val =~ /^\xfe\xff/
ABresult
0X0
100
111
1496 0 $charsetQuickTime = $et->Options('CharsetQuickTime');
1497 0 $enc = $charsetQuickTime;
1498 } else {
1499 4 ▶ $enc = $val=~s/^\xfe\xff// ? 'UTF16' : 'UTF8';
Branch: 1 branch
BranchTrueFalseTotal
$val =~ s/^\xfe\xff// ? : 0 4 4
1500 }
1501 4 ▶ unless ($$tagInfo{NoDecode}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tagInfo->{"NoDecode"}) 4 0 4
1502 4 $val = $et->Decode($val, $enc);
1503 4 $val =~ s/\0+$//; # remove trailing nulls if they exist
1504 }
1505 4 ▶ $val = $hdr . $val if defined $hdr;
Branch: 1 branch
BranchTrueFalseTotal
if defined $hdr 0 4 4
1506 4 my $langCode = UnpackLang($lang, 1);
1507 4 $langInfo = GetLangInfo($tagInfo, $langCode);
1508 4 $nvHash = $et->GetNewValueHash($langInfo);
1509 4 ▶ if (not $nvHash and $nvHashNoLang) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $nvHash and $nvHashNoLang) 3 1 4
Condition66%2/3
not $nvHash and $nvHashNoLang
!ll&&!rl&&r
013
MC/DC50%1/2
not $nvHash and $nvHashNoLang
not $nvHash $nvHashNoLang
Truth table66%2/3
not(A) and B
A= not $nvHashB= $nvHashNoLang
ABresult
0X0
100
111
1510 3 ▶ if ($lang eq $undLang and not $$didTag{$nvHashNoLang}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($lang eq $undLang and not $didTag->{$nvHashNoLang}) { } 3 0 3
elsif ($canCreate) { } 0 0 0
Condition33%1/3
$lang eq $undLang and not $didTag->{$nvHashNoLang}
!ll&&!rl&&r
003
MC/DC0%0/2
$lang eq $undLang and not $didTag->{$nvHashNoLang}
$lang eq $undLang not $didTag->{$nvHashNoLang}
Truth table33%1/3
A and not(B)
A= $lang eq $undLangB= not $didTag->{$nvHashNoLang}
ABresult
0X0
100
111
1511 3 $nvHash = $nvHashNoLang;
1512 } elsif ($canCreate) {
1513 # delete other languages when writing default
1514 0 my $grp = $et->GetGroup($langInfo, 1);
1515 0 $et->VerboseValue("- $grp:$$langInfo{Name}", $val);
1516 0 ++$$et{CHANGED};
1517 0 next;
1518 }
1519 }
1520 } else {
1521 0 $val = $buff;
1522 0 ▶ if ($tag =~ /^\xa9/ or $$tagInfo{IText}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ /^\xa9/ or $tagInfo->{"IText"}) 0 0 0
Condition0%0/3
$tag =~ /^\xa9/ or $tagInfo->{"IText"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$tag =~ /^\xa9/ or $tagInfo->{"IText"}
$tag =~ /^\xa9/ $tagInfo->{"IText"}
Truth table0%0/3
A or B
A= $tag =~ /^\xa9/B= $tagInfo->{"IText"}
ABresult
1X1
011
000
1523 0 $et->Warn("Corrupted $$tagInfo{Name} value");
1524 }
1525 }
1526 12 ▶ if ($nvHash and defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nvHash and defined $val) 3 9 12
Condition100%3/3
$nvHash and defined $val
!ll&&!rl&&r
183
MC/DC100%2/2
$nvHash and defined $val
$nvHash defined $val
Truth table100%3/3
A and B
A= $nvHashB= defined $val
ABresult
0X0
100
111
1527 3 ▶ if ($et->IsOverwriting($nvHash, $val)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->IsOverwriting($nvHash, $val)) 3 0 3
1528 3 $newData = $et->GetNewValue($nvHash);
1529 3 ▶ $newData = '' unless defined $newData or $canCreate;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $newData or $canCreate 0 3 3
Condition33%1/3
defined $newData or $canCreate
l!l&&r!l&&!r
300
MC/DC0%0/2
defined $newData or $canCreate
defined $newData $canCreate
Truth table33%1/3
A or B
A= defined $newDataB= $canCreate
ABresult
1X1
011
000
1530 3 ++$$et{CHANGED};
1531 3 my $grp = $et->GetGroup($langInfo, 1);
1532 3 $et->VerboseValue("- $grp:$$langInfo{Name}", $val);
1533 3 ▶ unless (defined $newData and not $$didTag{$nvHash}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $newData and not $didTag->{$nvHash}) 0 3 3
Condition33%1/3
defined $newData and not $didTag->{$nvHash}
!ll&&!rl&&r
003
MC/DC0%0/2
defined $newData and not $didTag->{$nvHash}
defined $newData not $didTag->{$nvHash}
Truth table33%1/3
A and not(B)
A= defined $newDataB= not $didTag->{$nvHash}
ABresult
0X0
100
111
1534 # must not delete items from iprp because it will mess up the ordering
1535 0 ▶ next unless defined $itemIndex;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $itemIndex 0 0 0
1536 }
1537 3 $et->VerboseValue("+ $grp:$$langInfo{Name}", $newData);
1538 # add back necessary header and encode as necessary
1539 3 ▶ if (defined $lang) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $lang) { } 3 0 3
elsif (not $format or $format =~ /^string/ and not $tagInfo->{'Binary'} and not $tagInfo->{'ValueConv'}) { } 0 0 0
elsif ($format and not $tagInfo->{'Binary'}) { } 0 0 0
1540 3 ▶ my $iText = $$tagInfo{IText} || 0;
Condition50%1/2
$tagInfo->{'IText'} || 0
l!l
03
MC/DC0%0/1
$tagInfo->{'IText'} || 0
$tagInfo->{'IText'}
Truth table50%1/2
A
A= $tagInfo->{'IText'}
Aresult
11
00
1541 3 my $hdr;
1542 3 ▶ if ($iText > 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($iText > 6) 0 3 3
1543 0 ▶ $newData .= ' 'x($iText-6) if length($newData) < $iText-6;
Branch: 1 branch
BranchTrueFalseTotal
if length $newData < $iText - 6 0 0 0
1544 0 $hdr = substr($newData, 0, $iText-6);
1545 0 $newData = substr($newData, $iText-6);
1546 }
1547 3 ▶ unless ($$tagInfo{NoDecode}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tagInfo->{"NoDecode"}) 3 0 3
1548 3 ▶ $newData = $et->Encode($newData, $lang < 0x400 ? $charsetQuickTime : 'UTF8');
Branch: 1 branch
BranchTrueFalseTotal
$lang < 1024 ? : 0 3 3
1549 }
1550 3 ▶ my $wLang = $lang eq $undLang ? 0 : $lang;
Branch: 1 branch
BranchTrueFalseTotal
$lang eq $undLang ? : 3 0 3
1551 3 ▶ if ($iText < 6) {
Branch: 2 branches
BranchTrueFalseTotal
if ($iText < 6) { } 3 0 3
elsif ($iText == 6) { } 0 0 0
1552 3 $newData = pack('nn', length($newData), $wLang) . $newData;
1553 } elsif ($iText == 6) {
1554 0 $newData = pack('Nn', 0, $wLang) . $newData . "\0";
1555 } else {
1556 0 $newData = "\0\0\0\0" . $hdr . pack('n', $wLang) . $newData . "\0";
1557 }
1558 ▶ } elsif (not $format or $format =~ /^string/ and
Condition0%0/9
not $format or $format =~ /^string/ and not $tagInfo->{"Binary"} and not $tagInfo->{"ValueConv"}
l!l&&r!l&&!r
000
$format =~ /^string/ and not $tagInfo->{"Binary"} and not $tagInfo->{"ValueConv"}
!ll&&!rl&&r
000
$format =~ /^string/ and not $tagInfo->{"Binary"}
!ll&&!rl&&r
000
MC/DC0%0/4
not $format or $format =~ /^string/ and not $tagInfo->{"Binary"} and not $tagInfo->{"ValueConv"}
not $format $format =~ /^string/ not $tagInfo->{"Binary"} not $tagInfo->{"ValueConv"}
Truth table0%0/5
not(A) or B and not(C) and not(D)
A= not $formatB= $format =~ /^string/C= not $tagInfo->{"Binary"}D= not $tagInfo->{"ValueConv"}
ABCDresult
1XXX1
01111
00XX0
010X0
01100
1559 not $$tagInfo{Binary} and not $$tagInfo{ValueConv})
1560 {
1561 # write all strings as UTF-8
1562 0 $newData = $et->Encode($newData, 'UTF8');
1563 ▶ } elsif ($format and not $$tagInfo{Binary}) {
Condition0%0/3
$format and not $tagInfo->{"Binary"}
!ll&&!rl&&r
000
MC/DC0%0/2
$format and not $tagInfo->{"Binary"}
$format not $tagInfo->{"Binary"}
Truth table0%0/3
A and not(B)
A= $formatB= not $tagInfo->{"Binary"}
ABresult
0X0
100
111
1564 # format new value for writing
1565 0 $newData = WriteValue($newData, $format, $$tagInfo{Count});
1566 }
1567 }
1568 3 $$didTag{$nvHash} = 1; # set flag so we don't add this tag again
1569 }
1570 }
1571 }
1572 # write the new atom if it was modified
1573 1181 ▶ if (defined $newData) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newData) 528 653 1181
1574 528 my $sizeDiff = length($buff) - length($newData);
1575 # pad to original size if specified, otherwise give verbose message about the changed size
1576 528 ▶ if ($sizeDiff > 0 and $$tagInfo{PreservePadding} and $et->Options('QuickTimePad')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($sizeDiff > 0 and $tagInfo->{'PreservePadding'} and $et->Options('QuickTimePad')) { } 0 528 528
elsif ($sizeDiff) { } 115 413 528
Condition83%5/6
$sizeDiff > 0 and $tagInfo->{"PreservePadding"} and $et->Options("QuickTimePad")
!ll&&!rl&&r
52080
$sizeDiff > 0 and $tagInfo->{"PreservePadding"}
!ll&&!rl&&r
464568
MC/DC0%0/3
$sizeDiff > 0 and $tagInfo->{"PreservePadding"} and $et->Options("QuickTimePad")
$sizeDiff > 0 $tagInfo->{"PreservePadding"} $et->Options("QuickTimePad")
Truth table75%3/4
A and B and C
A= $sizeDiff > 0B= $tagInfo->{"PreservePadding"}C= $et->Options("QuickTimePad")
ABCresult
0XX0
10X0
1100
1111
1577 0 $newData .= "\0" x $sizeDiff;
1578 0 $et->VPrint(1, " ($$tagInfo{Name} padded to original size)");
1579 } elsif ($sizeDiff) {
1580 115 $et->VPrint(1, " ($$tagInfo{Name} changed size)");
1581 }
1582 528 my $len = length($newData) + 8;
1583 528 ▶ $len > 0x7fffffff and $et->Error("$$tagInfo{Name} to large to write"), last;
Branch: 1 branch
BranchTrueFalseTotal
$len > 2147483647 and $et->Error(qq[$tagInfo->{"Name"} to large to write]), last 0 528 528
1584 # update size in ChunkOffset list for modified 'uuid' atom
1585 528 ▶ $$dirInfo{ChunkOffset}[-1][2] = $len if $tag eq 'uuid';
Branch: 1 branch
BranchTrueFalseTotal
if $tag eq "uuid" 5 523 528
1586 528 ▶ next unless $len > 8; # don't write empty atom header
Branch: 1 branch
BranchTrueFalseTotal
unless $len > 8 25 503 528
1587 # maintain pointer to chunk offsets if necessary
1588 503 ▶ if (@chunkOffset) {
Branch: 1 branch
BranchTrueFalseTotal
if (@chunkOffset) 198 305 503
1589 198 $$_[1] += 8 + length $$outfile foreach @chunkOffset;
1590 198 push @{$$dirInfo{ChunkOffset}}, @chunkOffset;
1591 }
1592 503 ▶ if ($$tagInfo{WriteLast}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{'WriteLast'}) { } 1 502 503
1593 1 ▶ $writeLast = ($writeLast || '') . Set32u($len) . $tag . $newData;
Condition50%1/2
$writeLast || ''
l!l
01
MC/DC0%0/1
$writeLast || ''
$writeLast
Truth table50%1/2
A
A= $writeLast
Aresult
11
00
1594 } else {
1595 502 $boxPos{$tag} = [ length($$outfile), length($newData) + 8 ];
1596 # write the updated directory with its atom header
1597 502 ▶ Write($outfile, Set32u($len), $tag, $newData) or $rtnVal=$rtnErr, $err=1, last;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, &Set32u($len), $tag, $newData) or $rtnVal = $rtnErr, $err = 1, last 502 0 502
1598 }
1599 503 next;
1600 }
1601 }
1602 # keep track of data references in this track
1603 733 ▶ if ($tag eq 'dinf') {
Branch: 3 branches
BranchTrueFalseTotal
if ($tag eq 'dinf') { } 0 733 733
elsif ($parent eq 'DataInfo' and length $buff >= 4) { } 43 690 733
elsif ($tag eq 'stsd' and length $buff >= 8) { } 43 1294 1337
1604 0 $$et{QtDataRef} = [ ]; # initialize list of data references
1605 ▶ } elsif ($parent eq 'DataInfo' and length($buff) >= 4) {
Condition66%2/3
$parent eq "DataInfo" and length $buff >= 4
!ll&&!rl&&r
690043
MC/DC50%1/2
$parent eq "DataInfo" and length $buff >= 4
$parent eq "DataInfo" length $buff >= 4
Truth table66%2/3
A and B
A= $parent eq "DataInfo"B= length $buff >= 4
ABresult
0X0
100
111
1606 # save data reference type and version/flags
1607 43 push @{$$et{QtDataRef}}, [ $tag, Get32u(\$buff,0) ];
1608 ▶ } elsif ($tag eq 'stsd' and length($buff) >= 8) {
Condition66%2/3
$tag eq "stsd" and length $buff >= 8
!ll&&!rl&&r
647043
MC/DC50%1/2
$tag eq "stsd" and length $buff >= 8
$tag eq "stsd" length $buff >= 8
Truth table66%2/3
A and B
A= $tag eq "stsd"B= length $buff >= 8
ABresult
0X0
100
111
1609 43 my $n = Get32u(\$buff, 4); # get number of sample descriptions in table
1610 43 my ($pos, $flg) = (8, 0);
1611 43 my ($i, $msg);
1612 43 ▶ for ($i=0; $i<$n; ++$i) { # loop through sample descriptions
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $n) 43 43 86
1613 43 ▶ $pos + 16 <= length($buff) or $msg = 'Truncated sample table', last;
Branch: 1 branch
BranchTrueFalseTotal
$pos + 16 <= length $buff or $msg = "Truncated sample table", last 43 0 43
1614 43 my $siz = Get32u(\$buff, $pos);
1615 43 ▶ $pos + $siz <= length($buff) or $msg = 'Truncated sample table', last;
Branch: 1 branch
BranchTrueFalseTotal
$pos + $siz <= length $buff or $msg = "Truncated sample table", last 43 0 43
1616 43 my $drefIdx = Get16u(\$buff, $pos + 14);
1617 43 my $drefTbl = $$et{QtDataRef};
1618 43 ▶ if (not $drefIdx) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $drefIdx) { } 0 43 43
elsif ($drefTbl and $$drefTbl[$drefIdx - 1]) { } 43 0 43
1619 0 $flg |= 0x01; # in this file if data reference index is 0 (if like iloc)
1620 ▶ } elsif ($drefTbl and $$drefTbl[$drefIdx-1]) {
Condition33%1/3
$drefTbl and $$drefTbl[$drefIdx - 1]
!ll&&!rl&&r
0043
MC/DC0%0/2
$drefTbl and $$drefTbl[$drefIdx - 1]
$drefTbl $$drefTbl[$drefIdx - 1]
Truth table33%1/3
A and B
A= $drefTblB= $$drefTbl[$drefIdx - 1]
ABresult
0X0
100
111
1621 43 my $dref = $$drefTbl[$drefIdx-1];
1622 # $flg = 0x01-in this file, 0x02-in some other file
1623 43 ▶ $flg |= ($$dref[1] == 1 and $$dref[0] ne 'rsrc') ? 0x01 : 0x02;
Branch: 1 branch
BranchTrueFalseTotal
$dref->[1] == 1 && $dref->[0] ne 'rsrc' ? : 43 0 43
Condition33%1/3
$dref->[1] == 1 and $dref->[0] ne "rsrc"
!ll&&!rl&&r
0043
MC/DC0%0/2
$dref->[1] == 1 and $dref->[0] ne "rsrc"
$dref->[1] == 1 $dref->[0] ne "rsrc"
Truth table33%1/3
A and B
A= $dref->[1] == 1B= $dref->[0] ne "rsrc"
ABresult
0X0
100
111
1624 } else {
1625 0 $msg = "No data reference for sample description $i";
1626 0 last;
1627 }
1628 43 $pos += $siz;
1629 }
1630 43 ▶ if ($msg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg) 0 43 43
1631 # (allow empty sample description for non-audio/video handler types, eg. 'url ', 'meta')
1632 # (also, incorrectly written 'mett' SampleEntry by Google phones,
1633 # see https://exiftool.org/forum/index.php?msg=91158)
1634 0 ▶ if ($avType{$$et{MediaType}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Image::ExifTool::QuickTime::avType{$et->{"MediaType"}}) 0 0 0
1635 0 ▶ my $grp = $$et{CUR_WRITE_GROUP} || $parent;
Condition0%0/3
$et->{'CUR_WRITE_GROUP'} || $parent
l!l&&r!l&&!r
000
MC/DC0%0/2
$et->{'CUR_WRITE_GROUP'} || $parent
$et->{'CUR_WRITE_GROUP'} $parent
Truth table0%0/3
A || B
A= $et->{'CUR_WRITE_GROUP'}B= $parent
ABresult
1X1
011
000
1636 0 $et->Error("$msg for $grp");
1637 0 return $rtnErr;
1638 }
1639 0 $flg = 1; # (this seems to be the case)
1640 }
1641 43 $$et{QtDataFlg} = $flg;
1642 43 ▶ if ($$et{AssumedDataRef}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"AssumedDataRef"}) 0 43 43
1643 0 ▶ if ($flg != $$et{AssumedDataRef}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flg != $et->{"AssumedDataRef"}) 0 0 0
1644 0 ▶ my $grp = $$et{CUR_WRITE_GROUP} || $parent;
Condition0%0/3
$et->{'CUR_WRITE_GROUP'} || $parent
l!l&&r!l&&!r
000
MC/DC0%0/2
$et->{'CUR_WRITE_GROUP'} || $parent
$et->{'CUR_WRITE_GROUP'} $parent
Truth table0%0/3
A || B
A= $et->{'CUR_WRITE_GROUP'}B= $parent
ABresult
1X1
011
000
1645 0 $et->Error("Assumed incorrect data reference for $grp (was $flg)");
1646 }
1647 0 delete $$et{AssumedDataRef};
1648 }
1649 }
1650 733 ▶ if ($tagInfo and $$tagInfo{WriteLast}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo and $tagInfo->{'WriteLast'}) { } 0 733 733
Condition66%2/3
$tagInfo and $tagInfo->{"WriteLast"}
!ll&&!rl&&r
806530
MC/DC0%0/2
$tagInfo and $tagInfo->{"WriteLast"}
$tagInfo $tagInfo->{"WriteLast"}
Truth table66%2/3
A and B
A= $tagInfoB= $tagInfo->{"WriteLast"}
ABresult
0X0
100
111
1651 0 ▶ $writeLast = ($writeLast || '') . $hdr . $buff;
Condition0%0/2
$writeLast || ''
l!l
00
MC/DC0%0/1
$writeLast || ''
$writeLast
Truth table0%0/2
A
A= $writeLast
Aresult
11
00
1652 } else {
1653 # save position of this box in the output buffer
1654 #TODO do this:
1655 #TODO my $bp = $boxPos{$tag} || ($boxPos{$tag} = [ ]);
1656 #TODO push @$bp, length($$outfile), length($hdr) + length($buff);
1657 #TODO instead of this:
1658 733 $boxPos{$tag} = [ length($$outfile), length($hdr) + length($buff) ];
1659 #TODO then we have the positions of all the infe boxes -- we then only need
1660 #TODO to know the index of the box to edit if the encoding changes for one of them
1661 # copy the existing atom
1662 733 ▶ Write($outfile, $hdr, $buff) or $rtnVal=$rtnErr, $err=1, last;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $hdr, $buff) or $rtnVal = $rtnErr, $err = 1, last 733 0 733
1663 }
1664 }
1665 # ($errStr is set if there was an error that could possibly be due to an unknown trailer)
1666 412 ▶ if ($errStr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($errStr) 0 412 412
1667 0 ▶ if (($lastTag eq 'mdat' or $lastTag eq 'moov') and not $dataPt and (not $$tagTablePtr{$tag} or
Branch: 1 branch
BranchTrueFalseTotal
if ($lastTag eq 'mdat' || $lastTag eq 'moov' and not $dataPt and !$tagTablePtr->{$tag} || ref $tagTablePtr->{$tag} eq 'HASH' && $tagTablePtr->{$tag}{'Unknown'}) { } 0 0 0
Condition0%0/15
$lastTag eq "mdat" || $lastTag eq "moov" and not $dataPt and !$tagTablePtr->{$tag} || ref $tagTablePtr->{$tag} eq "HASH" && $tagTablePtr->{$tag}{"Unknown"}
!ll&&!rl&&r
000
$lastTag eq "mdat" || $lastTag eq "moov" and not $dataPt
!ll&&!rl&&r
000
$lastTag eq "mdat" or $lastTag eq "moov"
l!l&&r!l&&!r
000
not $tagTablePtr->{$tag} or ref $tagTablePtr->{$tag} eq "HASH" and $tagTablePtr->{$tag}{"Unknown"}
l!l&&r!l&&!r
000
ref $tagTablePtr->{$tag} eq "HASH" and $tagTablePtr->{$tag}{"Unknown"}
!ll&&!rl&&r
000
MC/DC0%0/6
$lastTag eq "mdat" || $lastTag eq "moov" and not $dataPt and !$tagTablePtr->{$tag} || ref $tagTablePtr->{$tag} eq "HASH" && $tagTablePtr->{$tag}{"Unknown"}
$lastTag eq "mdat" $lastTag eq "moov" not $dataPt not $tagTablePtr->{$tag} ref $tagTablePtr->{$tag} eq "HASH" $tagTablePtr->{$tag}{"Unknown"}
Truth table0%0/11
A or B and not(C) and not(D) or E and F
A= $lastTag eq "mdat"B= $lastTag eq "moov"C= not $dataPtD= not $tagTablePtr->{$tag}E= ref $tagTablePtr->{$tag} eq "HASH"F= $tagTablePtr->{$tag}{"Unknown"}
ABCDEFresult
00XXXX0
1X0XXX0
010XXX0
1X100X0
1X10100
01100X0
0110100
1X11XX1
1X10111
0111XX1
0110111
1668 ref $$tagTablePtr{$tag} eq 'HASH' and $$tagTablePtr{$tag}{Unknown}))
1669 {
1670 # identify other known trailers from their first bytes
1671 0 $buf2 = '';
1672 0 ▶ $raf->Seek($lastPos,0) and $raf->Read($buf2,8);
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($lastPos, 0) and $raf->Read($buf2, 8) 0 0 0
1673 0 my ($type, $len);
1674 0 ▶ if ($buf2 eq 'CCCCCCCC') {
Branch: 2 branches
BranchTrueFalseTotal
if ($buf2 eq 'CCCCCCCC') { } 0 0 0
elsif ($buf2 =~ /^(gpsa|gps0|gsen|gsea)...\0/s) { } 0 0 0
1675 0 $type = 'Kenwood';
1676 } elsif ($buf2 =~ /^(gpsa|gps0|gsen|gsea)...\0/s) {
1677 0 $type = 'RIFF';
1678 } else {
1679 0 $type = 'Unknown';
1680 }
1681 # determine length of this trailer
1682 0 ▶ if ($trailer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trailer) { } 0 0 0
1683 0 $len = $$trailer[1] - $lastPos; # runs to start of next trailer
1684 } else {
1685 0 ▶ $raf->Seek(0, 2) or $et->Error('Seek error'), return $dataPt ? undef : 1;
Branch: 2 branches
BranchTrueFalseTotal
$raf->Seek(0, 2) or $et->Error("Seek error"), (return $dataPt ? undef : 1) 0 0 0
$dataPt ? : 0 0 0
1686 0 $len = $raf->Tell() - $lastPos; # runs to end of file
1687 }
1688 # add to start of linked list of trailers
1689 0 $trailer = [ $type, $lastPos, $len, $trailer ];
1690 } else {
1691 0 $et->Error($errStr);
1692 0 ▶ return $dataPt ? undef : 1;
Branch: 1 branch
BranchTrueFalseTotal
$dataPt ? : 0 0 0
1693 }
1694 }
1695 412 ▶ $et->VPrint(0, " [deleting $delCount $dirName tag".($delCount==1 ? '' : 's')."]\n") if $delCount;
Branch: 2 branches
BranchTrueFalseTotal
if $delCount 13 399 412
$delCount == 1 ? : 2 11 13
1696  
1697 # can finally set necessary variables for creating Video/AudioKeys tags
1698 412 ▶ if ($createKeys < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($createKeys < 0) 8 404 412
1699 8 ▶ if ($avType{$$et{MediaType}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Image::ExifTool::QuickTime::avType{$et->{'MediaType'}}) { } 8 0 8
1700 8 $createKeys = 1;
1701 8 ($keysGrp, $keysPath) = ("$avType{$$et{MediaType}}Keys", 'MOV-Movie-Track');
1702 } else {
1703 0 $canCreate = 0;
1704 }
1705 }
1706 412 ▶ $createKeys &= ~0x01 unless $$addDirs{$keysGrp}; # (Keys may have been written)
Branch: 1 branch
BranchTrueFalseTotal
unless $addDirs->{$keysGrp} 340 72 412
1707  
1708 # add new directories/tags at this level if necessary
1709 412 ▶ if ($canCreate and (exists $$et{EDIT_DIRS}{$dirName} or $createKeys)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($canCreate and exists $et->{"EDIT_DIRS"}{$dirName} || $createKeys) 129 283 412
Condition100%6/6
$canCreate and exists $et->{"EDIT_DIRS"}{$dirName} || $createKeys
!ll&&!rl&&r
24637129
exists $et->{"EDIT_DIRS"}{$dirName} or $createKeys
l!l&&r!l&&!r
121837
MC/DC100%3/3
$canCreate and exists $et->{"EDIT_DIRS"}{$dirName} || $createKeys
$canCreate exists $et->{"EDIT_DIRS"}{$dirName} $createKeys
Truth table100%4/4
A and B or C
A= $canCreateB= exists $et->{"EDIT_DIRS"}{$dirName}C= $createKeys
ABCresult
0XX0
1000
11X1
1011
1710 # get a hash of tagInfo references to add to this directory
1711 129 my $dirs = $et->GetAddDirHash($tagTablePtr, $dirName);
1712 # make sorted list of new tags to be added
1713 129 my @addTags = sort(keys(%$dirs), keys %$newTags);
1714 129 my ($tag, $index);
1715 # add Keys tags if necessary
1716 129 ▶ if ($createKeys) {
Branch: 1 branch
BranchTrueFalseTotal
if ($createKeys) 37 92 129
1717 37 ▶ if ($curPath eq $keysPath) {
Branch: 3 branches
BranchTrueFalseTotal
if ($curPath eq $keysPath) { } 7 30 37
elsif ($curPath eq "$keysPath-Meta") { } 10 20 30
elsif ($curPath eq "$keysPath-Meta-ItemList" and $et->{$keysGrp}) { } 20 0 20
1718 # add Meta for Keys if necessary
1719 7 ▶ unless ($didDir{meta}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($didDir{"meta"}) 7 0 7
1720 7 $$dirs{meta} = $Image::ExifTool::QuickTime::Movie{meta};
1721 7 push @addTags, 'meta';
1722 }
1723 } elsif ($curPath eq "$keysPath-Meta") {
1724 # special case for Keys Meta -- reset directories and start again
1725 10 undef @addTags;
1726 10 $dirs = { };
1727 10 foreach ('keys','ilst') {
1728 20 ▶ next if $didDir{$_}; # don't add again
Branch: 1 branch
BranchTrueFalseTotal
if $didDir{$_} 20 0 20
1729 0 $$dirs{$_} = $Image::ExifTool::QuickTime::Meta{$_};
1730 0 push @addTags, $_;
1731 }
1732 ▶ } elsif ($curPath eq "$keysPath-Meta-ItemList" and $$et{$keysGrp}) {
Condition33%1/3
$curPath eq "$keysPath-Meta-ItemList" and $et->{$keysGrp}
!ll&&!rl&&r
0020
MC/DC0%0/2
$curPath eq "$keysPath-Meta-ItemList" and $et->{$keysGrp}
$curPath eq "$keysPath-Meta-ItemList" $et->{$keysGrp}
Truth table33%1/3
A and B
A= $curPath eq "$keysPath-Meta-ItemList"B= $et->{$keysGrp}
ABresult
0X0
100
111
1733 20 foreach $index (sort { $a <=> $b } keys %{$$et{$keysGrp}{Add}}) {
1734 11 my $id = Set32u($index);
1735 11 $$newTags{$id} = $$et{$keysGrp}{Add}{$index};
1736 11 push @addTags, $id;
1737 }
1738 } else {
1739 0 $dirs = $et->GetAddDirHash($tagTablePtr, $dirName);
1740 0 push @addTags, sort keys %$dirs;
1741 }
1742 }
1743 # (note that $tag may be a binary Keys index here)
1744 129 foreach $tag (@addTags) {
1745 78 ▶ my $tagInfo = $$dirs{$tag} || $$newTags{$tag};
Condition66%2/3
$dirs->{$tag} || $newTags->{$tag}
l!l&&r!l&&!r
22560
MC/DC0%0/2
$dirs->{$tag} || $newTags->{$tag}
$dirs->{$tag} $newTags->{$tag}
Truth table66%2/3
A || B
A= $dirs->{$tag}B= $newTags->{$tag}
ABresult
1X1
011
000
1746 78 ▶ unless (ref $tagInfo eq 'HASH') { # (shouldn't happen, but somehow there is forum17260)
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $tagInfo eq "HASH") 0 78 78
1747 # (also can happen if Meta exists but Keys does not since 'keys' is an array ref.
1748 # SonyPMW-EX1R.mp4 has a Movie-Meta atom with XML and no Keys that triggers this
1749 # issue. Note that in this case the Meta HandlerType is 'meta' instead of 'mdta',
1750 # which isn't a problem for ExifTool, but may be for other software?)
1751 0 ▶ next unless ref $tagInfo eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tagInfo eq "ARRAY" 0 0 0
1752 0 ▶ $tagInfo = $et->GetTagInfo($tagTablePtr, $tag) or next;
Branch: 1 branch
BranchTrueFalseTotal
$tagInfo = $et->GetTagInfo($tagTablePtr, $tag) or next 0 0 0
1753 }
1754 78 ▶ next if defined $$tagInfo{CanCreate} and not $$tagInfo{CanCreate};
Branch: 1 branch
BranchTrueFalseTotal
if defined $tagInfo->{"CanCreate"} and not $tagInfo->{"CanCreate"} 0 78 78
Condition33%1/3
defined $tagInfo->{"CanCreate"} and not $tagInfo->{"CanCreate"}
!ll&&!rl&&r
7800
MC/DC0%0/2
defined $tagInfo->{"CanCreate"} and not $tagInfo->{"CanCreate"}
defined $tagInfo->{"CanCreate"} not $tagInfo->{"CanCreate"}
Truth table33%1/3
A and not(B)
A= defined $tagInfo->{"CanCreate"}B= not $tagInfo->{"CanCreate"}
ABresult
0X0
100
111
1755 78 ▶ next if defined $$tagInfo{MediaType} and $$et{MediaType} ne $$tagInfo{MediaType};
Branch: 1 branch
BranchTrueFalseTotal
if defined $tagInfo->{"MediaType"} and $et->{"MediaType"} ne $tagInfo->{"MediaType"} 0 78 78
Condition33%1/3
defined $tagInfo->{"MediaType"} and $et->{"MediaType"} ne $tagInfo->{"MediaType"}
!ll&&!rl&&r
7800
MC/DC0%0/2
defined $tagInfo->{"MediaType"} and $et->{"MediaType"} ne $tagInfo->{"MediaType"}
defined $tagInfo->{"MediaType"} $et->{"MediaType"} ne $tagInfo->{"MediaType"}
Truth table33%1/3
A and B
A= defined $tagInfo->{"MediaType"}B= $et->{"MediaType"} ne $tagInfo->{"MediaType"}
ABresult
0X0
100
111
1756 78 my $subdir = $$tagInfo{SubDirectory};
1757 78 ▶ unless ($subdir) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($subdir) 56 22 78
1758 56 my $nvHash = $et->GetNewValueHash($tagInfo);
1759 56 ▶ next unless $nvHash and not $$didTag{$nvHash};
Branch: 1 branch
BranchTrueFalseTotal
unless $nvHash and not $didTag->{$nvHash} 10 46 56
Condition66%2/3
$nvHash and not $didTag->{$nvHash}
!ll&&!rl&&r
01046
MC/DC50%1/2
$nvHash and not $didTag->{$nvHash}
$nvHash not $didTag->{$nvHash}
Truth table66%2/3
A and not(B)
A= $nvHashB= not $didTag->{$nvHash}
ABresult
0X0
100
111
1760 46 ▶ next unless $$nvHash{IsCreating} and $et->IsOverwriting($nvHash);
Branch: 1 branch
BranchTrueFalseTotal
unless $nvHash->{"IsCreating"} and $et->IsOverwriting($nvHash) 18 28 46
Condition66%2/3
$nvHash->{"IsCreating"} and $et->IsOverwriting($nvHash)
!ll&&!rl&&r
18028
MC/DC50%1/2
$nvHash->{"IsCreating"} and $et->IsOverwriting($nvHash)
$nvHash->{"IsCreating"} $et->IsOverwriting($nvHash)
Truth table66%2/3
A and B
A= $nvHash->{"IsCreating"}B= $et->IsOverwriting($nvHash)
ABresult
0X0
100
111
1761 28 my $newVal = $et->GetNewValue($nvHash);
1762 28 ▶ next unless defined $newVal;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $newVal 0 28 28
1763 28 my $prVal = $newVal;
1764 28 my $flags = FormatQTValue($et, \$newVal, $tagInfo);
1765 28 ▶ next unless defined $newVal;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $newVal 0 28 28
1766 28 my ($ctry, $lang) = (0, 0);
1767 # handle alternate languages
1768 28 ▶ if ($$tagInfo{LangCode}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{"LangCode"}) 2 26 28
1769 2 $tag = substr($tag, 0, 4); # strip language code from tag ID
1770 2 ▶ unless ($$tagInfo{LangCode} =~ /^([A-Z]{3})?[-_]?([A-Z]{2})?$/i) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tagInfo->{"LangCode"} =~ /^([A-Z]{3})?[-_]?([A-Z]{2})?$/i) 0 2 2
1771 0 $et->Warn("Invalid language code for $$tagInfo{Name}");
1772 0 next;
1773 }
1774 # pack language and country codes
1775 2 ▶ if ($1 and $1 ne 'und') {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 and $1 ne "und") 2 0 2
Condition33%1/3
$1 and $1 ne "und"
!ll&&!rl&&r
002
MC/DC0%0/2
$1 and $1 ne "und"
$1 $1 ne "und"
Truth table33%1/3
A and B
A= $1B= $1 ne "und"
ABresult
0X0
100
111
1776 2 $lang = ($lang << 5) | ($_ - 0x60) foreach unpack 'C*', lc($1);
1777 }
1778 2 ▶ $ctry = unpack('n', pack('a2',uc($2))) if $2 and $2 ne 'ZZ';
Branch: 1 branch
BranchTrueFalseTotal
if $2 and $2 ne "ZZ" 2 0 2
Condition33%1/3
$2 and $2 ne "ZZ"
!ll&&!rl&&r
002
MC/DC0%0/2
$2 and $2 ne "ZZ"
$2 $2 ne "ZZ"
Truth table33%1/3
A and B
A= $2B= $2 ne "ZZ"
ABresult
0X0
100
111
1779 }
1780 28 ▶ if ($$dirInfo{HasData}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($dirInfo->{'HasData'}) { } 20 8 28
elsif ($tag =~ /^\xa9/ or $tagInfo->{'IText'}) { } 8 0 8
elsif ($ctry or $lang) { } 0 0 0
1781 # add 'data' header
1782 20 $newVal = pack('Na4Nnn',16+length($newVal),'data',$flags,$ctry,$lang).$newVal;
1783 ▶ } elsif ($tag =~ /^\xa9/ or $$tagInfo{IText}) {
Condition66%2/3
$tag =~ /^\xa9/ or $tagInfo->{"IText"}
l!l&&r!l&&!r
620
MC/DC0%0/2
$tag =~ /^\xa9/ or $tagInfo->{"IText"}
$tag =~ /^\xa9/ $tagInfo->{"IText"}
Truth table66%2/3
A or B
A= $tag =~ /^\xa9/B= $tagInfo->{"IText"}
ABresult
1X1
011
000
1784 8 ▶ if ($ctry) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ctry) { } 0 8 8
elsif ($tagInfo->{'IText'} and $tagInfo->{'IText'} >= 6) { } 2 6 8
1785 0 my $grp = $et->GetGroup($tagInfo,1);
1786 0 $et->Warn("Can't use country code for $grp:$$tagInfo{Name}");
1787 0 next;
1788 ▶ } elsif ($$tagInfo{IText} and $$tagInfo{IText} >= 6) {
Condition66%2/3
$tagInfo->{"IText"} and $tagInfo->{"IText"} >= 6
!ll&&!rl&&r
602
MC/DC50%1/2
$tagInfo->{"IText"} and $tagInfo->{"IText"} >= 6
$tagInfo->{"IText"} $tagInfo->{"IText"} >= 6
Truth table66%2/3
A and B
A= $tagInfo->{"IText"}B= $tagInfo->{"IText"} >= 6
ABresult
0X0
100
111
1789 # add 6-byte langText header and trailing null
1790 # (with extra junk before language code if IText > 6)
1791 2 my $n = $$tagInfo{IText} - 6;
1792 2 ▶ $newVal .= ' ' x $n if length($newVal) < $n;
Branch: 1 branch
BranchTrueFalseTotal
if length $newVal < $n 0 2 2
1793 2 $newVal = "\0\0\0\0" . substr($newVal,0,$n) . pack('n',0,$lang) . substr($newVal,$n) . "\0";
1794 } else {
1795 # add IText header
1796 6 $newVal = pack('nn',length($newVal),$lang) . $newVal;
1797 }
1798 ▶ } elsif ($ctry or $lang) {
Condition0%0/3
$ctry or $lang
l!l&&r!l&&!r
000
MC/DC0%0/2
$ctry or $lang
$ctry $lang
Truth table0%0/3
A or B
A= $ctryB= $lang
ABresult
1X1
011
000
1799 0 my $grp = $et->GetGroup($tagInfo,1);
1800 0 $et->Warn("Can't use language code for $grp:$$tagInfo{Name}");
1801 0 next;
1802 }
1803 28 ▶ if ($$tagInfo{WriteLast}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{'WriteLast'}) { } 0 28 28
1804 0 ▶ $writeLast = ($writeLast || '') . Set32u(8+length($newVal)) . $tag . $newVal;
Condition0%0/2
$writeLast || ''
l!l
00
MC/DC0%0/1
$writeLast || ''
$writeLast
Truth table0%0/2
A
A= $writeLast
Aresult
11
00
1805 } else {
1806 28 $boxPos{$tag} = [ length($$outfile), 8 + length($newVal) ];
1807 28 ▶ Write($outfile, Set32u(8+length($newVal)), $tag, $newVal) or $rtnVal=$rtnErr, $err=1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, &Set32u(8 + length($newVal)), $tag, $newVal) or $rtnVal = $rtnErr, $err = 1 28 0 28
1808 }
1809 28 my $grp = $et->GetGroup($tagInfo, 1);
1810 28 $et->VerboseValue("+ $grp:$$tagInfo{Name}", $prVal);
1811 28 $$didTag{$nvHash} = 1;
1812 28 ++$$et{CHANGED};
1813 28 next;
1814 }
1815 22 ▶ my $subName = $$subdir{DirName} || $$tagInfo{Name};
Condition33%1/3
$subdir->{'DirName'} || $tagInfo->{'Name'}
l!l&&r!l&&!r
2200
MC/DC0%0/2
$subdir->{'DirName'} || $tagInfo->{'Name'}
$subdir->{'DirName'} $tagInfo->{'Name'}
Truth table33%1/3
A || B
A= $subdir->{'DirName'}B= $tagInfo->{'Name'}
ABresult
1X1
011
000
1816 # QuickTime hierarchy is complex, so check full directory path before adding
1817 22 ▶ if ($createKeys and $curPath eq $keysPath and $subName eq 'Meta') {
Branch: 3 branches
BranchTrueFalseTotal
if ($createKeys and $curPath eq $keysPath and $subName eq 'Meta') { } 7 15 22
elsif ($createKeys and $curPath eq "$keysPath-Meta") { } 0 15 15
elsif ($subName eq 'Meta' and $et->{'OPTIONS'}{'QuickTimeHandler'}) { } 3 12 15
Condition83%5/6
$createKeys and $curPath eq $keysPath and $subName eq "Meta"
!ll&&!rl&&r
1327
$createKeys and $curPath eq $keysPath
!ll&&!rl&&r
1309
MC/DC66%2/3
$createKeys and $curPath eq $keysPath and $subName eq "Meta"
$createKeys $curPath eq $keysPath $subName eq "Meta"
Truth table75%3/4
A and B and C
A= $createKeysB= $curPath eq $keysPathC= $subName eq "Meta"
ABCresult
0XX0
10X0
1100
1111
1818 7 $et->VPrint(0, " Creating Meta with mdta Handler and Keys\n");
1819 # init Meta box for Keys tags with mdta Handler and empty Keys+ItemList
1820 7 $buf2 = "\0\0\0\x20hdlr\0\0\0\0\0\0\0\0mdta\0\0\0\0\0\0\0\0\0\0\0\0" .
1821 "\0\0\0\x10keys\0\0\0\0\0\0\0\0" .
1822 "\0\0\0\x08ilst";
1823 ▶ } elsif ($createKeys and $curPath eq "$keysPath-Meta") {
Condition66%2/3
$createKeys and $curPath eq "$keysPath-Meta"
!ll&&!rl&&r
1320
MC/DC0%0/2
$createKeys and $curPath eq "$keysPath-Meta"
$createKeys $curPath eq "$keysPath-Meta"
Truth table66%2/3
A and B
A= $createKeysB= $curPath eq "$keysPath-Meta"
ABresult
0X0
100
111
1824 0 ▶ $buf2 = ($subName eq 'Keys' ? "\0\0\0\0\0\0\0\0" : '');
Branch: 1 branch
BranchTrueFalseTotal
$subName eq 'Keys' ? : 0 0 0
1825 ▶ } elsif ($subName eq 'Meta' and $$et{OPTIONS}{QuickTimeHandler}) {
Condition66%2/3
$subName eq "Meta" and $et->{"OPTIONS"}{"QuickTimeHandler"}
!ll&&!rl&&r
1203
MC/DC50%1/2
$subName eq "Meta" and $et->{"OPTIONS"}{"QuickTimeHandler"}
$subName eq "Meta" $et->{"OPTIONS"}{"QuickTimeHandler"}
Truth table66%2/3
A and B
A= $subName eq "Meta"B= $et->{"OPTIONS"}{"QuickTimeHandler"}
ABresult
0X0
100
111
1826 3 $et->VPrint(0, " Creating Meta with mdir Handler\n");
1827 # init Meta box for ItemList tags with mdir Handler
1828 3 $buf2 = "\0\0\0\x20hdlr\0\0\0\0\0\0\0\0mdir\0\0\0\0\0\0\0\0\0\0\0\0";
1829 } else {
1830 12 ▶ next unless $curPath eq $writePath and $$addDirs{$subName} and $$addDirs{$subName} eq $dirName;
Branch: 1 branch
BranchTrueFalseTotal
unless $curPath eq $writePath and $addDirs->{$subName} and $addDirs->{$subName} eq $dirName 0 12 12
Condition33%2/6
$curPath eq $writePath and $addDirs->{$subName} and $addDirs->{$subName} eq $dirName
!ll&&!rl&&r
0012
$curPath eq $writePath and $addDirs->{$subName}
!ll&&!rl&&r
0012
MC/DC0%0/3
$curPath eq $writePath and $addDirs->{$subName} and $addDirs->{$subName} eq $dirName
$curPath eq $writePath $addDirs->{$subName} $addDirs->{$subName} eq $dirName
Truth table25%1/4
A and B and C
A= $curPath eq $writePathB= $addDirs->{$subName}C= $addDirs->{$subName} eq $dirName
ABCresult
0XX0
10X0
1100
1111
1831 12 $buf2 = ''; # write from scratch
1832 }
1833 my %subdirInfo = (
1834 Parent => $dirName,
1835 DirName => $subName,
1836 DataPt => \$buf2,
1837 DirStart => 0,
1838 HasData => $$subdir{HasData},
1839 OutFile => $outfile,
1840 ChunkOffset => [ ], # (just to be safe)
1841 WriteGroup => $$tagInfo{WriteGroup},
1842 22 );
1843 22 my $subTable = GetTagTable($$subdir{TagTable});
1844 22 my $newData = $et->WriteDirectory(\%subdirInfo, $subTable, $$subdir{WriteProc});
1845 22 ▶ if ($newData and length($newData) <= 0x7ffffff7) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newData and length $newData <= 2147483639) 22 0 22
Condition33%1/3
$newData and length $newData <= 2147483639
!ll&&!rl&&r
0022
MC/DC0%0/2
$newData and length $newData <= 2147483639
$newData length $newData <= 2147483639
Truth table33%1/3
A and B
A= $newDataB= length $newData <= 2147483639
ABresult
0X0
100
111
1846 22 my $prefix = '';
1847 # add atom version or ID if necessary
1848 22 ▶ if ($$subdir{Start}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subdir->{"Start"}) 6 16 22
1849 6 ▶ if ($$subdir{Start} == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subdir->{'Start'} == 4) { } 3 3 6
1850 3 $prefix = "\0\0\0\0"; # a simple version number
1851 } else {
1852 # get UUID from Condition expression
1853 3 my $cond = $$tagInfo{Condition};
1854 3 ▶ $prefix = eval qq("$1") if $cond and $cond =~ m{=~\s*\/\^(.*)/};
Branch: 1 branch
BranchTrueFalseTotal
if $cond and $cond =~ m[=~\s*\/\^(.*)/] 3 0 3
Condition33%1/3
$cond and $cond =~ m[=~\s*\/\^(.*)/]
!ll&&!rl&&r
003
MC/DC0%0/2
$cond and $cond =~ m[=~\s*\/\^(.*)/]
$cond $cond =~ m[=~\s*\/\^(.*)/]
Truth table33%1/3
A and B
A= $condB= $cond =~ m[=~\s*\/\^(.*)/]
ABresult
0X0
100
111
1855 3 ▶ length($prefix) == $$subdir{Start} or $et->Error('Internal UUID error');
Branch: 1 branch
BranchTrueFalseTotal
length $prefix == $subdir->{"Start"} or $et->Error("Internal UUID error") 3 0 3
1856 }
1857 }
1858 22 my $newHdr = Set32u(8+length($newData)+length($prefix)) . $tag . $prefix;
1859 22 ▶ if ($$tagInfo{WriteLast}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{'WriteLast'}) { } 1 21 22
1860 1 ▶ $writeLast = ($writeLast || '') . $newHdr . $newData;
Condition50%1/2
$writeLast || ''
l!l
01
MC/DC0%0/1
$writeLast || ''
$writeLast
Truth table50%1/2
A
A= $writeLast
Aresult
11
00
1861 } else {
1862 21 ▶ if ($tag eq 'uuid') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq "uuid") 2 19 21
1863 # add offset for new uuid (needed for CR3 CTBO offsets)
1864 2 my $off = $$dirInfo{ChunkOffset};
1865 2 push @$off, [ $tag, length($$outfile), length($newHdr) + length($newData) ];
1866 }
1867 21 $boxPos{$tag} = [ length($$outfile), length($newHdr) + length($newData) ];
1868 21 ▶ Write($outfile, $newHdr, $newData) or $rtnVal=$rtnErr, $err=1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $newHdr, $newData) or $rtnVal = $rtnErr, $err = 1 21 0 21
1869 }
1870 }
1871 # add only once (must delete _after_ call to WriteDirectory())
1872 # (Keys tags are a special case, and are handled separately)
1873 22 ▶ delete $$addDirs{$subName} unless $createKeys;
Branch: 1 branch
BranchTrueFalseTotal
unless $createKeys 13 9 22
1874 }
1875 }
1876 # write HEIC metadata after top-level 'meta' box has been processed if editing this information
1877 412 ▶ if ($curPath eq 'MOV-Meta' and $$et{EDIT_DIRS}{ItemInformation}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($curPath eq "MOV-Meta" and $et->{"EDIT_DIRS"}{"ItemInformation"}) 3 409 412
Condition66%2/3
$curPath eq "MOV-Meta" and $et->{"EDIT_DIRS"}{"ItemInformation"}
!ll&&!rl&&r
40903
MC/DC50%1/2
$curPath eq "MOV-Meta" and $et->{"EDIT_DIRS"}{"ItemInformation"}
$curPath eq "MOV-Meta" $et->{"EDIT_DIRS"}{"ItemInformation"}
Truth table66%2/3
A and B
A= $curPath eq "MOV-Meta"B= $et->{"EDIT_DIRS"}{"ItemInformation"}
ABresult
0X0
100
111
1878 3 $$dirInfo{BoxPos} = \%boxPos;
1879 3 my $mdatEdit = WriteItemInfo($et, $dirInfo, $outfile);
1880 3 ▶ if ($mdatEdit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mdatEdit) 3 0 3
1881 3 ▶ $et->Error('Multiple top-level Meta containers') if $$et{mdatEdit};
Branch: 1 branch
BranchTrueFalseTotal
if $et->{"mdatEdit"} 0 3 3
1882 3 $$et{mdatEdit} = $mdatEdit;
1883 }
1884 }
1885 # write out any necessary terminator
1886 412 ▶ Write($outfile, $term) or $rtnVal=$rtnErr, $err=1 if $term and length $$outfile;
Branch: 1 branch
BranchTrueFalseTotal
if $term and length $$outfile 0 412 412
Condition22%2/9
$term && length $$outfile && (&Write($outfile, $term) || ($rtnVal = $rtnErr, $err = 1))
!ll&&!rl&&r
41200
$term and length $$outfile
!ll&&!rl&&r
41200
&Write($outfile, $term) or $rtnVal = $rtnErr, $err = 1
l!l&&r!l&&!r
000
MC/DC0%0/4
$term && length $$outfile && (&Write($outfile, $term) || ($rtnVal = $rtnErr, $err = 1))
$term length $$outfile &Write($outfile, $term) $rtnVal = $rtnErr, $err = 1
Truth table20%1/5
A and B && C or D
A= $termB= length $$outfileC= &Write($outfile, $term)D= $rtnVal = $rtnErr, $err = 1
ABCDresult
0XXX0
10XX0
11000
111X1
11011
1887  
1888 # delete temporary Keys variables after Meta is processed
1889 412 ▶ if ($dirName eq 'Meta') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirName eq "Meta") 40 372 412
1890 # delete any Meta box with no useful information (ie. only 'hdlr','keys','lang','ctry')
1891 40 my $isEmpty = 1;
1892 40 ▶ $emptyMeta{$_} or $isEmpty = 0, last foreach keys %boxPos;
Branch: 1 branch
BranchTrueFalseTotal
$emptyMeta{$_} or $isEmpty = 0, last 30 34 64
1893 40 ▶ if ($isEmpty) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isEmpty) 6 34 40
1894 6 ▶ $et->VPrint(0,' Deleting ' . join('+', sort map { $emptyMeta{$_} } keys %boxPos)) if %boxPos;
Branch: 1 branch
BranchTrueFalseTotal
if %boxPos 6 0 6
1895 6 $$outfile = '';
1896 # (could report a file if editing nothing when it contained an empty Meta atom)
1897 # ++$$et{CHANGED};
1898 }
1899 40 ▶ if ($curPath eq "$keysPath-Meta") {
Branch: 1 branch
BranchTrueFalseTotal
if ($curPath eq "$keysPath-Meta") 20 20 40
1900 20 delete $$addDirs{$keysGrp}; # prevent creation of another Meta for Keys tags
1901 20 delete $$et{$keysGrp};
1902 }
1903 }
1904  
1905 # return now if writing subdirectory
1906 412 ▶ if ($dataPt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dataPt) 389 23 412
1907 389 ▶ $et->Error("Internal error: WriteLast not on top-level atom!\n") if $writeLast;
Branch: 1 branch
BranchTrueFalseTotal
if $writeLast 0 389 389
1908 389 ▶ return $err ? undef : $$outfile;
Branch: 1 branch
BranchTrueFalseTotal
$err ? : 0 389 389
1909 }
1910  
1911 # issue minor error if we didn't find an 'mdat' atom
1912 23 my $off = $$dirInfo{ChunkOffset};
1913 23 ▶ if (not @mdat) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@mdat) 0 23 23
1914 0 foreach $co (@$off) {
1915 0 ▶ next if $$co[0] eq 'uuid';
Branch: 1 branch
BranchTrueFalseTotal
if $co->[0] eq "uuid" 0 0 0
1916 0 $et->Error('Media data referenced but not found');
1917 0 return $rtnVal;
1918 }
1919 0 $et->Warn('No media data', 1);
1920 }
1921  
1922 # edit mdat blocks as required
1923 # (0=old pos [0 if creating], 1=old end [0 if creating], 2=new data ref or undef to delete,
1924 # 3=new data item id)
1925 23 ▶ if ($$et{mdatEdit}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"mdatEdit"}) 3 20 23
1926 3 @mdatEdit = @{$$et{mdatEdit}};
1927 3 delete $$et{mdatEdit};
1928 }
1929 23 foreach $edit (@mdatEdit) {
1930 5 my (@thisMdat, @newMdat, $changed);
1931 5 foreach $mdat (@mdat) {
1932 # keep track of all chunks for the mdat with this header
1933 12 ▶ if (length $$mdat[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $mdat->[2]) 10 2 12
1934 10 push @newMdat, @thisMdat;
1935 10 undef @thisMdat;
1936 }
1937 12 push @thisMdat, $mdat;
1938 # is this edit inside this mdat chunk?
1939 # - $$edit[0] and $$edit[1] will both be zero if we are creating a new chunk
1940 # - $$mdat[1] is zero if mdat runs to end of file
1941 # - $$edit[0] == $$edit[1] == $$mdat[0] if reviving a deleted chunk
1942 # - $$mdat[5] is defined if this was a newly added/edited chunk
1943 12 ▶ next if defined $$mdat[5] or $changed; # don't replace a newly added chunk
Branch: 1 branch
BranchTrueFalseTotal
if defined $mdat->[5] or $changed 7 5 12
Condition100%3/3
defined $mdat->[5] or $changed
l!l&&r!l&&!r
255
MC/DC100%2/2
defined $mdat->[5] or $changed
defined $mdat->[5] $changed
Truth table100%3/3
A or B
A= defined $mdat->[5]B= $changed
ABresult
1X1
011
000
1944 5 ▶ if (not $$edit[0] or # (newly created chunk)
Branch: 1 branch
BranchTrueFalseTotal
if (not $edit->[0] or ($edit->[0] < $mdat->[1] || !$mdat->[1] and $edit->[1] > $mdat->[0] or $edit->[0] == $edit->[1] and $edit->[0] == $mdat->[0] || $edit->[0] == $mdat->[1])) 5 0 5
Condition50%9/18
not $edit->[0] or ($edit->[0] < $mdat->[1] || !$mdat->[1] and $edit->[1] > $mdat->[0] or $edit->[0] == $edit->[1] and $edit->[0] == $mdat->[0] || $edit->[0] == $mdat->[1])
l!l&&r!l&&!r
230
$edit->[0] < $mdat->[1] || !$mdat->[1] and $edit->[1] > $mdat->[0] or $edit->[0] == $edit->[1] and $edit->[0] == $mdat->[0] || $edit->[0] == $mdat->[1]
l!l&&r!l&&!r
210
$edit->[0] < $mdat->[1] || !$mdat->[1] and $edit->[1] > $mdat->[0]
!ll&&!rl&&r
012
$edit->[0] < $mdat->[1] or not $mdat->[1]
l!l&&r!l&&!r
300
$edit->[0] == $edit->[1] and $edit->[0] == $mdat->[0] || $edit->[0] == $mdat->[1]
!ll&&!rl&&r
001
$edit->[0] == $mdat->[0] or $edit->[0] == $mdat->[1]
l!l&&r!l&&!r
100
MC/DC0%0/7
not $edit->[0] or ($edit->[0] < $mdat->[1] || !$mdat->[1] and $edit->[1] > $mdat->[0] or $edit->[0] == $edit->[1] and $edit->[0] == $mdat->[0] || $edit->[0] == $mdat->[1])
not $edit->[0] $edit->[0] < $mdat->[1] not $mdat->[1] $edit->[1] > $mdat->[0] $edit->[0] == $edit->[1] $edit->[0] == $mdat->[0] $edit->[0] == $mdat->[1]
Truth table20%3/15
not(A) or B or not(C) and D or E and F or G
A= not $edit->[0]B= $edit->[0] < $mdat->[1]C= not $mdat->[1]D= $edit->[1] > $mdat->[0]E= $edit->[0] == $edit->[1]F= $edit->[0] == $mdat->[0]G= $edit->[0] == $mdat->[1]
ABCDEFGresult
1XXXXXX1
01X1XXX1
0011XXX1
000X11X1
000X1011
01X011X1
01X01011
001011X1
00101011
000X0XX0
000X1000
01X00XX0
01X01000
00100XX0
00101000
1945 # (edit is inside chunk)
1946 ((($$edit[0] < $$mdat[1] or not $$mdat[1]) and $$edit[1] > $$mdat[0]) or
1947 # (edit inserted at start or end of chunk)
1948 ($$edit[0] == $$edit[1] and ($$edit[0] == $$mdat[0] or $$edit[0] == $$mdat[1]))))
1949 {
1950 5 ▶ if (not $$edit[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $edit->[0]) { } 2 3 5
elsif ($edit->[0] < $mdat->[0] or $edit->[1] > $mdat->[1] and $mdat->[1]) { } 0 6 6
1951 2 $$edit[0] = $$edit[1] = $$mdat[0]; # insert at start of this mdat
1952 ▶ } elsif ($$edit[0] < $$mdat[0] or ($$edit[1] > $$mdat[1] and $$mdat[1])) {
Condition33%2/6
$edit->[0] < $mdat->[0] or $edit->[1] > $mdat->[1] and $mdat->[1]
l!l&&r!l&&!r
003
$edit->[1] > $mdat->[1] and $mdat->[1]
!ll&&!rl&&r
300
MC/DC0%0/3
$edit->[0] < $mdat->[0] or $edit->[1] > $mdat->[1] and $mdat->[1]
$edit->[0] < $mdat->[0] $edit->[1] > $mdat->[1] $mdat->[1]
Truth table25%1/4
A or B and C
A= $edit->[0] < $mdat->[0]B= $edit->[1] > $mdat->[1]C= $mdat->[1]
ABCresult
1XX1
0111
00X0
0100
1953 0 $et->Error('ItemInfo runs across mdat boundary');
1954 0 return $rtnVal;
1955 }
1956 5 my $hdrChunk = $thisMdat[0];
1957 5 ▶ $hdrChunk or $et->Error('Internal error finding mdat header'), return $rtnVal;
Branch: 1 branch
BranchTrueFalseTotal
$hdrChunk or $et->Error("Internal error finding mdat header"), (return $rtnVal) 5 0 5
1958 # calculate difference in mdat size
1959 5 ▶ my $diff = ($$edit[2] ? length(${$$edit[2]}) : 0) - ($$edit[1] - $$edit[0]);
Branch: 1 branch
BranchTrueFalseTotal
$edit->[2] ? : 5 0 5
1960 # edit size of mdat in header if necessary
1961 5 ▶ if ($diff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($diff) 5 0 5
1962 5 ▶ if (length($$hdrChunk[2]) == 8) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $hdrChunk->[2] == 8) { } 5 0 5
elsif (length $hdrChunk->[2] == 16) { } 0 0 0
1963 5 my $size = Get32u(\$$hdrChunk[2], 0);
1964 5 ▶ if ($size) { # (0 size = extends to end of file)
Branch: 1 branch
BranchTrueFalseTotal
if ($size) 5 0 5
1965 5 $size += $diff;
1966 5 ▶ $size > 0xffffffff and $et->Error("Can't yet grow mdat across 4GB boundary"), return $rtnVal;
Branch: 1 branch
BranchTrueFalseTotal
$size > 4294967295 and $et->Error("Can't yet grow mdat across 4GB boundary"), (return $rtnVal) 0 5 5
1967 5 Set32u($size, \$$hdrChunk[2], 0);
1968 }
1969 } elsif (length($$hdrChunk[2]) == 16) {
1970 0 my $size = Get64u(\$$hdrChunk[2], 8);
1971 0 ▶ if ($size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size) 0 0 0
1972 0 $size += $diff;
1973 0 Set64u($size, \$$hdrChunk[2], 8);
1974 }
1975 } else {
1976 0 $et->Error('Internal error. Invalid mdat header');
1977 0 return $rtnVal;
1978 }
1979 }
1980 5 $changed = 1;
1981 # remove the edited section of this chunk (if any) and replace with new data (if any)
1982 5 ▶ if ($$edit[0] > $$mdat[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($edit->[0] > $mdat->[0]) { } 0 5 5
1983 0 ▶ push @thisMdat, [ $$edit[0], $$edit[1], '', 0, $$edit[2], $$edit[3] ] if $$edit[2];
Branch: 1 branch
BranchTrueFalseTotal
if $edit->[2] 0 0 0
1984 # add remaining data after edit (or empty stub in case it is referenced by an offset)
1985 0 push @thisMdat, [ $$edit[1], $$mdat[1], '' ];
1986 0 $$mdat[1] = $$edit[0]; # now ends at start of edit
1987 } else {
1988 5 ▶ if ($$edit[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($edit->[2]) 5 0 5
1989 # insert the new chunk before this chunk, moving the header to the new chunk
1990 5 splice @thisMdat, -1, 0, [ $$edit[0],$$edit[1],$$mdat[2],0,$$edit[2],$$edit[3] ];
1991 5 $$mdat[2] = ''; # (header was moved to new chunk)
1992 # initialize ChunkOffset pointer if necessary
1993 5 ▶ if ($$edit[3]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($edit->[3]) 5 0 5
1994 5 my $n = 0;
1995 5 foreach $co (@$off) {
1996 19 ▶ next unless defined $$co[4] and $$co[4] == $$edit[3];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $co->[4] and $co->[4] == $edit->[3] 14 5 19
Condition66%2/3
defined $co->[4] and $co->[4] == $edit->[3]
!ll&&!rl&&r
0145
MC/DC50%1/2
defined $co->[4] and $co->[4] == $edit->[3]
defined $co->[4] $co->[4] == $edit->[3]
Truth table66%2/3
A and B
A= defined $co->[4]B= $co->[4] == $edit->[3]
ABresult
0X0
100
111
1997 5 ++$n;
1998 5 ▶ if ($$co[0] eq 'stco_iloc') {
Branch: 1 branch
BranchTrueFalseTotal
if ($co->[0] eq 'stco_iloc') { } 5 0 5
1999 5 Set32u($$mdat[0], $outfile, $$co[1]);
2000 } else {
2001 0 Set64u($$mdat[0], $outfile, $$co[1]);
2002 }
2003 }
2004 5 ▶ $n == 1 or $et->Error('Internal error updating chunk offsets');
Branch: 1 branch
BranchTrueFalseTotal
$n == 1 or $et->Error("Internal error updating chunk offsets") 5 0 5
2005 }
2006 }
2007 5 $$mdat[0] = $$edit[1]; # remove old data
2008 }
2009 }
2010 }
2011 5 ▶ if ($changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($changed) { } 5 0 5
2012 5 @mdat = ( @newMdat, @thisMdat );
2013 5 ++$$et{CHANGED};
2014 } else {
2015 0 $et->Error('Internal error modifying mdat');
2016 }
2017 }
2018  
2019 # determine our new mdat positions
2020 # (0=old pos, 1=old end, 2=mdat header, 3=new pos, 4=new data ref if changed, 5=new item ID)
2021 23 my $pos = length $$outfile;
2022 23 foreach $mdat (@mdat) {
2023 31 $pos += length $$mdat[2];
2024 31 $$mdat[3] = $pos;
2025 31 ▶ $pos += $$mdat[4] ? length(${$$mdat[4]}) : $$mdat[1] - $$mdat[0];
Branch: 1 branch
BranchTrueFalseTotal
$mdat->[4] ? : 5 26 31
2026 }
2027  
2028 # fix up offsets for new mdat position(s) (and uuid positions in CR3 images)
2029 23 foreach $co (@$off) {
2030 69 my ($type, $ptr, $len, $base, $id) = @$co;
2031 69 ▶ $base = 0 unless $base;
Branch: 1 branch
BranchTrueFalseTotal
unless $base 69 0 69
2032 69 ▶ unless ($type =~ /^(stco|co64)_?(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type =~ /^(stco|co64)_?(.*)$/) 15 54 69
2033 15 ▶ next if $type eq 'uuid';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "uuid" 12 3 15
2034 3 ▶ $type eq 'CTBO' or $et->Error('Internal error fixing offsets'), last;
Branch: 1 branch
BranchTrueFalseTotal
$type eq "CTBO" or $et->Error("Internal error fixing offsets"), last 3 0 3
2035 # update 'CTBO' item offsets/sizes in Canon CR3 images
2036 3 ▶ $$co[2] > 12 or $et->Error('Invalid CTBO atom'), last;
Branch: 1 branch
BranchTrueFalseTotal
$co->[2] > 12 or $et->Error("Invalid CTBO atom"), last 3 0 3
2037 3 ▶ @mdat or $et->Error('Missing CR3 image data'), last;
Branch: 1 branch
BranchTrueFalseTotal
@mdat or $et->Error("Missing CR3 image data"), last 3 0 3
2038 3 my $n = Get32u($outfile, $$co[1] + 8);
2039 3 ▶ $$co[2] < $n * 20 + 12 and $et->Error('Truncated CTBO atom'), last;
Branch: 1 branch
BranchTrueFalseTotal
$co->[2] < $n * 20 + 12 and $et->Error("Truncated CTBO atom"), last 0 3 3
2040 3 my (%ctboOff, $i);
2041 # determine uuid types, and build an offset lookup based on CTBO ID number
2042 3 foreach (@$off) {
2043 25 ▶ next unless $$_[0] eq 'uuid' and $$_[2] >= 24; # (ignore undersized and deleted uuid boxes)
Branch: 1 branch
BranchTrueFalseTotal
unless $_->[0] eq "uuid" and $_->[2] >= 24 15 10 25
Condition66%2/3
$_->[0] eq "uuid" and $_->[2] >= 24
!ll&&!rl&&r
15010
MC/DC50%1/2
$_->[0] eq "uuid" and $_->[2] >= 24
$_->[0] eq "uuid" $_->[2] >= 24
Truth table66%2/3
A and B
A= $_->[0] eq "uuid"B= $_->[2] >= 24
ABresult
0X0
100
111
2044 10 my $pos = $$_[1];
2045 10 ▶ next if $pos + 24 > length $$outfile; # (will happen for WriteLast uuid tags)
Branch: 1 branch
BranchTrueFalseTotal
if $pos + 24 > length $$outfile 1 9 10
2046 9 my $siz = Get32u($outfile, $pos); # get size of uuid atom
2047 9 ▶ if ($siz == 1) { # check for extended (8-byte) size
Branch: 1 branch
BranchTrueFalseTotal
if ($siz == 1) 0 9 9
2048 0 ▶ next unless $$_[2] >= 32;
Branch: 1 branch
BranchTrueFalseTotal
unless $_->[2] >= 32 0 0 0
2049 0 $pos += 8;
2050 }
2051 # get CTBO entry ID based on 16-byte UUID identifier
2052 9 my $id = $ctboID{substr($$outfile, $pos+8, 16)};
2053 9 ▶ $ctboOff{$id} = $_ if defined $id;
Branch: 1 branch
BranchTrueFalseTotal
if defined $id 6 3 9
2054 }
2055 # calculate new offset for the first mdat (size of -1 indicates it didn't change)
2056 3 $ctboOff{3} = [ 'mdat', $mdat[0][3] - length $mdat[0][2], -1 ];
2057 3 ▶ for ($i=0; $i<$n; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $n) 12 3 15
2058 12 my $pos = $$co[1] + 12 + $i * 20;
2059 12 my $id = Get32u($outfile, $pos);
2060 # ignore if size is zero unless we can add this entry
2061 # (note: can't yet add/delete PreviewImage, but leave this possibility open)
2062 12 ▶ next unless Get64u($outfile, $pos + 12) or $id == 1 or $id == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless &Get64u($outfile, $pos + 12) or $id == 1 or $id == 2 3 9 12
Condition66%4/6
&Get64u($outfile, $pos + 12) or $id == 1 or $id == 2
l!l&&r!l&&!r
903
&Get64u($outfile, $pos + 12) or $id == 1
l!l&&r!l&&!r
903
MC/DC33%1/3
&Get64u($outfile, $pos + 12) or $id == 1 or $id == 2
&Get64u($outfile, $pos + 12) $id == 1 $id == 2
Truth table50%2/4
A or B or C
A= &Get64u($outfile, $pos + 12)B= $id == 1C= $id == 2
ABCresult
1XX1
01X1
0011
0000
2063 9 ▶ if (not defined $ctboOff{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ctboOff{$id}) 0 9 9
2064 0 ▶ $id==1 or $id==2 or $et->Error("Can't handle CR3 CTBO ID number $id"), last;
Branch: 1 branch
BranchTrueFalseTotal
$id == 1 or $id == 2 or $et->Error("Can't handle CR3 CTBO ID number $id"), last 0 0 0
Condition0%0/3
$id == 1 or $id == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$id == 1 or $id == 2
$id == 1 $id == 2
Truth table0%0/3
A or B
A= $id == 1B= $id == 2
ABresult
1X1
011
000
2065 # XMP or PreviewImage was deleted -- set offset and size to zero
2066 0 $ctboOff{$id} = [ 'uuid', 0, 0 ];
2067 }
2068 # update the new offset and size of this entry
2069 9 Set64u($ctboOff{$id}[1], $outfile, $pos + 4);
2070 9 ▶ Set64u($ctboOff{$id}[2], $outfile, $pos + 12) unless $ctboOff{$id}[2] < 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $ctboOff{$id}[2] < 0 6 3 9
2071 }
2072 3 next;
2073 }
2074 54 ▶ my $siz = $1 eq 'co64' ? 8 : 4;
Branch: 1 branch
BranchTrueFalseTotal
$1 eq 'co64' ? : 12 42 54
2075 54 my ($n, $tag);
2076 54 ▶ if ($2) { # is this an offset in an iloc or 'gps ' atom?
Branch: 1 branch
BranchTrueFalseTotal
if ($2) { } 11 43 54
2077 11 $n = 1;
2078 11 $type = $1;
2079 11 $tag = $2;
2080 } else { # this is an stco or co84 atom
2081 43 ▶ next if $len < 8;
Branch: 1 branch
BranchTrueFalseTotal
if $len < 8 0 43 43
2082 43 $n = Get32u($outfile, $ptr + 4); # get number of entries in table
2083 43 $ptr += 8;
2084 43 $len -= 8;
2085 43 $tag = $1;
2086 }
2087 54 my $end = $ptr + $n * $siz;
2088 54 ▶ $end > $ptr + $len and $et->Error("Invalid $tag table"), return $rtnVal;
Branch: 1 branch
BranchTrueFalseTotal
$end > $ptr + $len and $et->Error("Invalid $tag table"), (return $rtnVal) 0 54 54
2089 54 ▶ for (; $ptr<$end; $ptr+=$siz) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ptr < $end) 23 54 77
2090 23 my ($ok, $i);
2091 23 ▶ my $val = $type eq 'co64' ? Get64u($outfile, $ptr) : Get32u($outfile, $ptr);
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'co64' ? : 12 11 23
2092 23 ▶ for ($i=0; $i<@mdat; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @mdat) 38 0 38
2093 38 $mdat = $mdat[$i];
2094 38 my $pos = $val + $base;
2095 38 ▶ if (defined $$mdat[5]) { # is this chunk associated with an item we edited?
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mdat->[5]) { } 17 21 38
2096 # set offset only for the corresponding new chunk
2097 17 ▶ unless (defined $id and $id == $$mdat[5]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $id and $id == $mdat->[5]) 12 5 17
Condition66%2/3
defined $id and $id == $mdat->[5]
!ll&&!rl&&r
0125
MC/DC50%1/2
defined $id and $id == $mdat->[5]
defined $id $id == $mdat->[5]
Truth table66%2/3
A and B
A= defined $idB= $id == $mdat->[5]
ABresult
0X0
100
111
2098 # could have pointed to empty chunk before inserted chunk
2099 12 ▶ next unless $pos == $$mdat[0] and $$mdat[0] != $$mdat[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $pos == $mdat->[0] and $mdat->[0] != $mdat->[1] 12 0 12
Condition66%2/3
$pos == $mdat->[0] and $mdat->[0] != $mdat->[1]
!ll&&!rl&&r
930
MC/DC0%0/2
$pos == $mdat->[0] and $mdat->[0] != $mdat->[1]
$pos == $mdat->[0] $mdat->[0] != $mdat->[1]
Truth table66%2/3
A and B
A= $pos == $mdat->[0]B= $mdat->[0] != $mdat->[1]
ABresult
0X0
100
111
2100 }
2101 } else {
2102 # (have seen $pos == $$mdat[1], which is a real PITA)
2103 21 ▶ next unless $pos >= $$mdat[0] and ($pos <= $$mdat[1] or not $$mdat[1]);
Branch: 1 branch
BranchTrueFalseTotal
unless $pos >= $mdat->[0] and $pos <= $mdat->[1] || !$mdat->[1] 3 18 21
Condition66%4/6
$pos >= $mdat->[0] and $pos <= $mdat->[1] || !$mdat->[1]
!ll&&!rl&&r
0318
$pos <= $mdat->[1] or not $mdat->[1]
l!l&&r!l&&!r
1803
MC/DC33%1/3
$pos >= $mdat->[0] and $pos <= $mdat->[1] || !$mdat->[1]
$pos >= $mdat->[0] $pos <= $mdat->[1] not $mdat->[1]
Truth table50%2/4
A and B or not(C)
A= $pos >= $mdat->[0]B= $pos <= $mdat->[1]C= not $mdat->[1]
ABCresult
0XX0
1000
11X1
1011
2104 # step to next chunk if contiguous and at the end of this one
2105 18 ▶ next if $pos == $$mdat[1] and $i+1 < @mdat and $pos == $mdat[$i+1][0];
Branch: 1 branch
BranchTrueFalseTotal
if $pos == $mdat->[1] and $i + 1 < @mdat and $pos == $mdat[$i + 1][0] 0 18 18
Condition33%2/6
$pos == $mdat->[1] and $i + 1 < @mdat and $pos == $mdat[$i + 1][0]
!ll&&!rl&&r
1800
$pos == $mdat->[1] and $i + 1 < @mdat
!ll&&!rl&&r
1800
MC/DC0%0/3
$pos == $mdat->[1] and $i + 1 < @mdat and $pos == $mdat[$i + 1][0]
$pos == $mdat->[1] $i + 1 < @mdat $pos == $mdat[$i + 1][0]
Truth table25%1/4
A and B and C
A= $pos == $mdat->[1]B= $i + 1 < @mdatC= $pos == $mdat[$i + 1][0]
ABCresult
0XX0
10X0
1100
1111
2106 }
2107 23 $val += $$mdat[3] - $$mdat[0];
2108 23 ▶ if ($val < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val < 0) 0 23 23
2109 0 $et->Error("Error fixing up $tag offset");
2110 0 return $rtnVal;
2111 }
2112 23 ▶ if ($type eq 'co64') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'co64') { } 12 11 23
elsif ($val <= 4294967295) { } 11 0 11
2113 12 Set64u($val, $outfile, $ptr);
2114 } elsif ($val <= 0xffffffff) {
2115 11 Set32u($val, $outfile, $ptr);
2116 } else {
2117 0 $et->Error("Can't yet promote $tag offset to 64 bits");
2118 0 return $rtnVal;
2119 }
2120 23 $ok = 1;
2121 23 last;
2122 }
2123 23 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 23 23
2124 0 $et->Error("Chunk offset in $tag atom is outside media data");
2125 0 return $rtnVal;
2126 }
2127 }
2128 }
2129  
2130 # switch back to actual output file
2131 23 $outfile = $$dirInfo{OutFile};
2132  
2133 # write the metadata
2134 23 ▶ Write($outfile, $outBuff) or $rtnVal = 0;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $outBuff) or $rtnVal = 0 23 0 23
2135  
2136 # write the media data
2137 23 foreach $mdat (@mdat) {
2138 31 ▶ Write($outfile, $$mdat[2]) or $rtnVal = 0; # write mdat header
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $mdat->[2]) or $rtnVal = 0 31 0 31
2139 31 ▶ if ($$mdat[4]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mdat->[4]) { } 5 26 31
2140 5 ▶ Write($outfile, ${$$mdat[4]}) or $rtnVal = 0;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, ${$$mdat[4];}) or $rtnVal = 0 5 0 5
2141 } else {
2142 26 ▶ $raf->Seek($$mdat[0], 0) or $et->Error('Seek error'), last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($mdat->[0], 0) or $et->Error("Seek error"), last 26 0 26
2143 26 ▶ if ($$mdat[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mdat->[1]) { } 26 0 26
2144 26 my $result = Image::ExifTool::CopyBlock($raf, $outfile, $$mdat[1] - $$mdat[0]);
2145 26 ▶ defined $result or $rtnVal = 0, last;
Branch: 1 branch
BranchTrueFalseTotal
defined $result or $rtnVal = 0, last 26 0 26
2146 26 ▶ $result or $et->Error("Truncated mdat atom"), last;
Branch: 1 branch
BranchTrueFalseTotal
$result or $et->Error("Truncated mdat atom"), last 26 0 26
2147 } else {
2148 # mdat continues to end of file
2149 0 ▶ while ($raf->Read($buf2, 65536)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raf->Read($buf2, 65536)) 0 0 0
2150 0 ▶ Write($outfile, $buf2) or $rtnVal = 0, last;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $buf2) or $rtnVal = 0, last 0 0 0
2151 }
2152 }
2153 }
2154 }
2155  
2156 # write the stuff that must come last
2157 23 ▶ Write($outfile, $writeLast) or $rtnVal = 0 if $writeLast;
Branch: 1 branch
BranchTrueFalseTotal
if $writeLast 2 21 23
Condition50%3/6
$writeLast && (&Write($outfile, $writeLast) || ($rtnVal = 0))
!ll&&!rl&&r
2120
&Write($outfile, $writeLast) or $rtnVal = 0
l!l&&r!l&&!r
200
MC/DC0%0/3
$writeLast && (&Write($outfile, $writeLast) || ($rtnVal = 0))
$writeLast &Write($outfile, $writeLast) $rtnVal = 0
Truth table0%0/4
A && B or C
A= $writeLastB= &Write($outfile, $writeLast)C= $rtnVal = 0
ABCresult
0XX0
1000
11X1
1011
2158  
2159 # copy trailers if necessary
2160 23 ▶ while ($rtnVal and $trailer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rtnVal and $trailer) 0 23 23
Condition33%1/3
$rtnVal and $trailer
!ll&&!rl&&r
0230
MC/DC0%0/2
$rtnVal and $trailer
$rtnVal $trailer
Truth table33%1/3
A and B
A= $rtnValB= $trailer
ABresult
0X0
100
111
2161 # are we deleting the trailers?
2162 0 my $nvTrail = $et->GetNewValueHash($Image::ExifTool::Extra{Trailer});
2163 0 ▶ if ($$et{DEL_GROUP}{Trailer} or $$et{DEL_GROUP}{$$trailer[0]} or
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"DEL_GROUP"}{"Trailer"} or $et->{"DEL_GROUP"}{$trailer->[0]} or $nvTrail and not $nvTrail->{"Value"} && $nvTrail->{"Value"}[0]) 0 0 0
Condition0%0/12
$et->{"DEL_GROUP"}{"Trailer"} or $et->{"DEL_GROUP"}{$trailer->[0]} or $nvTrail and not $nvTrail->{"Value"} && $nvTrail->{"Value"}[0]
l!l&&r!l&&!r
000
$et->{"DEL_GROUP"}{"Trailer"} or $et->{"DEL_GROUP"}{$trailer->[0]}
l!l&&r!l&&!r
000
$nvTrail and not $nvTrail->{"Value"} && $nvTrail->{"Value"}[0]
!ll&&!rl&&r
000
$nvTrail->{'Value'} && $nvTrail->{'Value'}[0]
!ll&&!rl&&r
000
MC/DC0%0/5
$et->{"DEL_GROUP"}{"Trailer"} or $et->{"DEL_GROUP"}{$trailer->[0]} or $nvTrail and not $nvTrail->{"Value"} && $nvTrail->{"Value"}[0]
$et->{"DEL_GROUP"}{"Trailer"} $et->{"DEL_GROUP"}{$trailer->[0]} $nvTrail $nvTrail->{'Value'} $nvTrail->{'Value'}[0]
Truth table0%0/6
A or B or C and not(D && E)
A= $et->{"DEL_GROUP"}{"Trailer"}B= $et->{"DEL_GROUP"}{$trailer->[0]}C= $nvTrailD= $nvTrail->{'Value'}E= $nvTrail->{'Value'}[0]
ABCDEresult
1XXXX1
01XXX1
0010X1
001101
000XX0
001110
2164 ($nvTrail and not ($$nvTrail{Value} and $$nvTrail{Value}[0])))
2165 {
2166 0 $et->Warn("Deleted $$trailer[0] trailer", 1);
2167 0 ++$$et{CHANGED};
2168 0 $trailer = $$trailer[3];
2169 0 next;
2170 }
2171 0 ▶ $raf->Seek($$trailer[1], 0) or $rtnVal = 0, last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($trailer->[1], 0) or $rtnVal = 0, last 0 0 0
2172 0 ▶ if ($$trailer[0] eq 'MIE') {
Branch: 1 branch
BranchTrueFalseTotal
if ($trailer->[0] eq 'MIE') { } 0 0 0
2173 0 require Image::ExifTool::MIE;
2174 0 my %dirInfo = ( RAF => $raf, OutFile => $outfile );
2175 0 my $result = Image::ExifTool::MIE::ProcessMIE($et, \%dirInfo);
2176 0 ▶ $result > 0 or $et->Error('Error writing MIE trailer'), $rtnVal = 0, last;
Branch: 1 branch
BranchTrueFalseTotal
$result > 0 or $et->Error("Error writing MIE trailer"), $rtnVal = 0, last 0 0 0
2177 } else {
2178 0 $et->Warn(sprintf('Copying %s trailer from offset 0x%x (%d bytes)', @$trailer[0..2]), 1);
2179 0 my $len = $$trailer[2];
2180 0 ▶ while ($len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len) 0 0 0
2181 0 ▶ my $n = $len > 65536 ? 65536 : $len;
Branch: 1 branch
BranchTrueFalseTotal
$len > 65536 ? : 0 0 0
2182 0 ▶ $raf->Read($buf2, $n) == $n and Write($outfile, $buf2) or $rtnVal = 0, last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buf2, $n) == $n and &Write($outfile, $buf2) or $rtnVal = 0, last 0 0 0
Condition0%0/3
$raf->Read($buf2, $n) == $n and &Write($outfile, $buf2)
!ll&&!rl&&r
000
MC/DC0%0/2
$raf->Read($buf2, $n) == $n and &Write($outfile, $buf2)
$raf->Read($buf2, $n) == $n &Write($outfile, $buf2)
Truth table0%0/3
A and B
A= $raf->Read($buf2, $n) == $nB= &Write($outfile, $buf2)
ABresult
0X0
100
111
2183 0 $len -= $n;
2184 }
2185 0 ▶ $rtnVal or $et->Error("Error copying $$trailer[0] trailer"), last;
Branch: 1 branch
BranchTrueFalseTotal
$rtnVal or $et->Error("Error copying $trailer->[0] trailer"), last 0 0 0
2186 }
2187 0 $trailer = $$trailer[3]; # step to next trailer in linked list
2188 }
2189 23 return $rtnVal;
2190 }
2191  
2192 #------------------------------------------------------------------------------
2193 # Write QuickTime-format MOV/MP4 file
2194 # Inputs: 0) ExifTool ref, 1) dirInfo ref
2195 # Returns: 1 on success, 0 if this wasn't a valid QuickTime file,
2196 # or -1 if a write error occurred
2197 sub WriteMOV($$)
2198 23 ▶{
Subroutine WriteMOV: called CC=16 SCAR=28.8
Pod undocumented
2199 23 my ($et, $dirInfo) = @_;
2200 23 ▶ $et or return 1; # allow dummy access to autoload this package
Branch: 1 branch
BranchTrueFalseTotal
$et or return 1 23 0 23
2201 23 ▶ my $raf = $$dirInfo{RAF} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $raf = $dirInfo->{"RAF"} or return 0 23 0 23
2202 23 my ($buff, $ftype);
2203  
2204 # read the first atom header
2205 23 ▶ return 0 unless $raf->Read($buff, 8) == 8;
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Read($buff, 8) == 8 0 23 23
2206 23 my ($size, $tag) = unpack('Na4', $buff);
2207 23 ▶ return 0 if $size < 8 and $size != 1;
Branch: 1 branch
BranchTrueFalseTotal
if $size < 8 and $size != 1 0 23 23
Condition33%1/3
$size < 8 and $size != 1
!ll&&!rl&&r
2300
MC/DC0%0/2
$size < 8 and $size != 1
$size < 8 $size != 1
Truth table33%1/3
A and B
A= $size < 8B= $size != 1
ABresult
0X0
100
111
2208  
2209 # validate the file format
2210 23 my $tagTablePtr = GetTagTable('Image::ExifTool::QuickTime::Main');
2211 23 ▶ return 0 unless $$tagTablePtr{$tag};
Branch: 1 branch
BranchTrueFalseTotal
unless $tagTablePtr->{$tag} 0 23 23
2212  
2213 # determine the file type (by default, assume MP4 if 'ftyp' exists
2214 # without 'qt ' as a compatible brand, but HEIC is an exception)
2215 23 ▶ if ($tag eq 'ftyp' and $size >= 12 and $size < 100000 and
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq 'ftyp' and $size >= 12 and $size < 100000 and $raf->Read($buff, $size - 8) == $size - 8 and not $buff =~ /^(....)+(qt )/s) { } 9 14 23
Condition66%8/12
$tag eq "ftyp" and $size >= 12 and $size < 100000 and $raf->Read($buff, $size - 8) == $size - 8 and not $buff =~ /^(....)+(qt )/s
!ll&&!rl&&r
1409
$tag eq "ftyp" and $size >= 12 and $size < 100000 and $raf->Read($buff, $size - 8) == $size - 8
!ll&&!rl&&r
1409
$tag eq "ftyp" and $size >= 12 and $size < 100000
!ll&&!rl&&r
1409
$tag eq "ftyp" and $size >= 12
!ll&&!rl&&r
1409
MC/DC20%1/5
$tag eq "ftyp" and $size >= 12 and $size < 100000 and $raf->Read($buff, $size - 8) == $size - 8 and not $buff =~ /^(....)+(qt )/s
$tag eq "ftyp" $size >= 12 $size < 100000 $raf->Read($buff, $size - 8) == $size - 8 not $buff =~ /^(....)+(qt )/s
Truth table33%2/6
A and B and C and D and not(E)
A= $tag eq "ftyp"B= $size >= 12C= $size < 100000D= $raf->Read($buff, $size - 8) == $size - 8E= not $buff =~ /^(....)+(qt )/s
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
2216 $raf->Read($buff, $size-8) == $size-8 and
2217 $buff !~ /^(....)+(qt )/s)
2218 {
2219 9 ▶ if ($buff =~ /^crx /) {
Branch: 2 branches
BranchTrueFalseTotal
if ($buff =~ /^crx /) { } 3 6 9
elsif ($buff =~ /^(heic|mif1|msf1|heix|hevc|hevx|avif)/) { } 3 3 6
2220 3 $ftype = 'CR3',
2221 } elsif ($buff =~ /^(heic|mif1|msf1|heix|hevc|hevx|avif)/) {
2222 3 $ftype = 'HEIC';
2223 } else {
2224 3 $ftype = 'MP4';
2225 }
2226 } else {
2227 14 $ftype = 'MOV';
2228 }
2229 23 $et->SetFileType($ftype); # need to set "FileType" tag for a Condition
2230 23 ▶ if ($ftype eq 'HEIC') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ftype eq 'HEIC') { } 3 20 23
2231 # EXIF is preferred in HEIC files
2232 3 $et->InitWriteDirs($dirMap{$ftype}, 'EXIF', 'QuickTime');
2233 } else {
2234 20 $et->InitWriteDirs($dirMap{$ftype}, 'XMP', 'QuickTime');
2235 }
2236 23 $$et{DirMap} = $dirMap{$ftype}; # need access to directory map when writing
2237 # track tags globally to avoid creating multiple tags in the case of duplicate directories
2238 23 $$et{DidTag} = { };
2239 23 SetByteOrder('MM');
2240 23 $raf->Seek(0,0);
2241  
2242 # write the file
2243 23 $$et{MediaType} = '';
2244 23 $$dirInfo{Parent} = '';
2245 23 $$dirInfo{DirName} = 'MOV';
2246 23 $$dirInfo{ChunkOffset} = [ ]; # (just to be safe)
2247 23 ▶ return WriteQuickTime($et, $dirInfo, $tagTablePtr) ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
&WriteQuickTime($et, $dirInfo, $tagTablePtr) ? : 23 0 23
2248 }
2249  
2250 23 1; # end
2251  
2252 __END__
« Image/ExifTool/WriteExif.pl ↑ Summary Image/ExifTool/Exif.pm »