@@ -80,23 +80,36 @@ public function getName(): string
80
80
return rtrim ($ str , "\0" );
81
81
}
82
82
83
+ /**
84
+ * @return int<1, max>
85
+ */
83
86
public function getSize (): int
84
87
{
85
88
if (array_key_exists ('size ' , $ this ->pax )) {
86
- return (int )$ this ->pax ['size ' ];
89
+ $ size = (int )$ this ->pax ['size ' ];
90
+ } else {
91
+ $ size = rtrim (substr ($ this ->content , 124 , 12 ));
92
+ if (preg_match ('/^[0-7]+$/D ' , $ size ) !== 1 ) {
93
+ throw new InvalidArchiveFormatException (
94
+ sprintf (
95
+ "Invalid Tar header format, file size must be octal number, '%s' got instead " ,
96
+ $ size
97
+ )
98
+ );
99
+ }
100
+ $ size = (int )octdec ($ size );
87
101
}
88
102
89
- $ str = rtrim (substr ($ this ->content , 124 , 12 ));
90
- if (preg_match ('/^[0-7]+$/D ' , $ str ) !== 1 ) {
103
+ if ($ size < 1 ) {
91
104
throw new InvalidArchiveFormatException (
92
105
sprintf (
93
- "Invalid Tar header format, file size must be octal number, '%s' got instead " ,
94
- $ str
106
+ "Invalid Tar header format, file size must be positive number, '%s' got instead " ,
107
+ $ size
95
108
)
96
109
);
97
110
}
98
111
99
- return ( int ) octdec ( $ str ) ;
112
+ return $ size ;
100
113
}
101
114
102
115
public function mergePaxHeader (Header $ header ): void
0 commit comments