@@ -31,6 +31,9 @@ public function getPath(JSignParam $params): string
3131
3232 if ($ downloadUrl && $ javaPath ) {
3333 $ baseDir = preg_replace ('/\/bin\/java$/ ' , '' , $ javaPath );
34+ if (!is_string ($ baseDir )) {
35+ throw new InvalidArgumentException ('Invalid JsignParamPath ' );
36+ }
3437 if (!is_dir ($ baseDir )) {
3538 $ ok = mkdir ($ baseDir , 0755 , true );
3639 if ($ ok === false ) {
@@ -52,13 +55,19 @@ private function validateVersion(JSignParam $params): bool
5255 {
5356 $ javaPath = $ params ->getJavaPath ();
5457 $ baseDir = preg_replace ('/\/bin\/java$/ ' , '' , $ javaPath );
58+ if (!is_string ($ baseDir )) {
59+ throw new InvalidArgumentException ('Invalid JsignParamPath ' );
60+ }
5561 $ lastVersion = $ baseDir . '/.java_version_ ' . basename ($ params ->getJavaDownloadUrl ());
5662 return file_exists ($ lastVersion );
5763 }
5864
5965 private function downloadAndExtract (string $ url , string $ baseDir ): void
6066 {
6167 $ baseDir = preg_replace ('/\/bin\/java$/ ' , '' , $ baseDir );
68+ if (!is_string ($ baseDir )) {
69+ throw new InvalidArgumentException ('Invalid JsignParamPath ' );
70+ }
6271
6372 if (!is_dir ($ baseDir )) {
6473 $ ok = mkdir ($ baseDir , 0755 , true );
@@ -76,7 +85,7 @@ private function downloadAndExtract(string $url, string $baseDir): void
7685 throw new InvalidArgumentException ('The file ' . $ baseDir . '/java.tar.gz cannot be extracted ' );
7786 }
7887 $ rootDirInsideTar = $ this ->findRootDir ($ tar , $ baseDir . '/java.tar.gz ' );
79- if (! $ rootDirInsideTar ) {
88+ if (empty ( $ rootDirInsideTar) ) {
8089 throw new InvalidArgumentException ('Invalid tar content. ' );
8190 }
8291 $ tar ->extractTo (directory: $ baseDir , overwrite: true );
@@ -91,9 +100,12 @@ private function downloadAndExtract(string $url, string $baseDir): void
91100 chmod ($ baseDir . '/bin/java ' , 0700 );
92101 }
93102
94- private function findRootDir (PharData $ phar , $ rootDir ) {
103+ private function findRootDir (PharData $ phar , string $ rootDir ): string {
95104 $ files = new \RecursiveIteratorIterator ($ phar , \RecursiveIteratorIterator::CHILD_FIRST );
96105 $ rootDir = realpath ($ rootDir );
106+ if (!is_string ($ rootDir ) || empty ($ rootDir )) {
107+ throw new InvalidArgumentException ('Invalid tar content. ' );
108+ }
97109
98110 foreach ($ files as $ file ) {
99111 $ pathName = $ file ->getPathname ();
@@ -104,6 +116,7 @@ private function findRootDir(PharData $phar, $rootDir) {
104116 return trim ($ parts [0 ], '/ ' );
105117 }
106118 }
119+ return '' ;
107120 }
108121
109122 private function chunkDownload (string $ url , string $ destination ): void
@@ -112,6 +125,9 @@ private function chunkDownload(string $url, string $destination): void
112125
113126 if ($ fp ) {
114127 $ ch = curl_init ($ url );
128+ if ($ ch === false ) {
129+ throw new InvalidArgumentException ('Failure to download file using the url ' . $ url );
130+ }
115131 curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
116132 curl_setopt ($ ch , CURLOPT_FILE , $ fp );
117133 curl_setopt ($ ch , CURLOPT_FOLLOWLOCATION , true );
0 commit comments