1- /* $Id: ExtPackUtil.cpp 110684 2025-08-11 17:18:47Z klaus.espenlaub @oracle.com $ */
1+ /* $Id: ExtPackUtil.cpp 111663 2025-11-12 12:07:32Z knut.osmundsen @oracle.com $ */
22/* * @file
33 * VirtualBox Main - Extension Pack Utilities and definitions, VBoxC, VBoxSVC, ++.
44 */
@@ -1206,14 +1206,26 @@ int VBoxExtPackValidateMember(const char *pszName, RTVFSOBJTYPE enmType, RTVFSOB
12061206int VBoxExtPackOpenTarFss (RTFILE hTarballFile, char *pszError, size_t cbError, PRTVFSFSSTREAM phTarFss,
12071207 PRTMANIFEST phFileManifest)
12081208{
1209+ int vrc;
1210+ 12091211 Assert (cbError > 0 );
12101212 *pszError = ' 0円 ' ;
12111213 *phTarFss = NIL_RTVFSFSSTREAM;
12121214
1215+ /*
1216+ * Read the first couple of bytes to detect the compression type.
1217+ */
1218+ uint8_t abFirstBytes[16 ] = {0 };
1219+ size_t cbFirstBytes = 0 ;
1220+ vrc = RTFileReadAt (hTarballFile, 0 , abFirstBytes, sizeof (abFirstBytes), &cbFirstBytes);
1221+ if (RT_FAILURE (vrc))
1222+ return vboxExtPackReturnError (vrc, pszError, cbError,
1223+ ExtPackUtil::tr (" Failed to read the first 16 bytes of the tarball: %Rrc" ), vrc);
1224+ 12131225 /*
12141226 * Rewind the file and set up a VFS chain for it.
12151227 */
1216- int vrc = RTFileSeek (hTarballFile, 0 , RTFILE_SEEK_BEGIN, NULL );
1228+ vrc = RTFileSeek (hTarballFile, 0 , RTFILE_SEEK_BEGIN, NULL );
12171229 if (RT_FAILURE (vrc))
12181230 return vboxExtPackReturnError (vrc, pszError, cbError,
12191231 ExtPackUtil::tr (" Failed seeking to the start of the tarball: %Rrc" ), vrc);
@@ -1233,16 +1245,36 @@ int VBoxExtPackOpenTarFss(RTFILE hTarballFile, char *pszError, size_t cbError, P
12331245 true /* read*/ , &hPtIos);
12341246 if (RT_SUCCESS (vrc))
12351247 {
1236- RTVFSIOSTREAM hGunzipIos;
1237- vrc = RTZipGzipDecompressIoStream (hPtIos, 0 /* fFlags*/ , &hGunzipIos);
1248+ RTVFSIOSTREAM hDecompIos = NIL_RTVFSIOSTREAM;
1249+ const char *pszDecompNm;
1250+ vrc = VERR_NOT_SUPPORTED;
1251+ if (RTZipXzIsStartOfCompressedStream (abFirstBytes, cbFirstBytes))
1252+ {
1253+ pszDecompNm = " RTZipXzDecompressIoStream" ;
1254+ #ifdef VBOX_WITH_LIBLZMA
1255+ vrc = RTZipXzDecompressIoStream (hPtIos, 0 /* fFlags*/ , &hDecompIos);
1256+ #endif
1257+ }
1258+ else if (RTZipBzip2IsStartOfCompressedStream (abFirstBytes, cbFirstBytes))
1259+ {
1260+ pszDecompNm = " RTZipBzip2DecompressIoStream" ;
1261+ #ifdef VBOX_WITH_LIBBZIP2
1262+ vrc = RTZipBzip2DecompressIoStream (hPtIos, 0 /* fFlags*/ , &hDecompIos);
1263+ #endif
1264+ }
1265+ else
1266+ {
1267+ pszDecompNm = " RTZipGzipDecompressIoStream" ;
1268+ vrc = RTZipGzipDecompressIoStream (hPtIos, 0 /* fFlags*/ , &hDecompIos);
1269+ }
12381270 if (RT_SUCCESS (vrc))
12391271 {
12401272 RTVFSFSSTREAM hTarFss;
1241- vrc = RTZipTarFsStreamFromIoStream (hGunzipIos , 0 /* fFlags*/ , &hTarFss);
1273+ vrc = RTZipTarFsStreamFromIoStream (hDecompIos , 0 /* fFlags*/ , &hTarFss);
12421274 if (RT_SUCCESS (vrc))
12431275 {
12441276 RTVfsIoStrmRelease (hPtIos);
1245- RTVfsIoStrmRelease (hGunzipIos );
1277+ RTVfsIoStrmRelease (hDecompIos );
12461278 RTVfsIoStrmRelease (hTarballIos);
12471279 *phTarFss = hTarFss;
12481280 if (phFileManifest)
@@ -1253,10 +1285,10 @@ int VBoxExtPackOpenTarFss(RTFILE hTarballFile, char *pszError, size_t cbError, P
12531285 }
12541286
12551287 vboxExtPackSetError (pszError, cbError, ExtPackUtil::tr (" RTZipTarFsStreamFromIoStream failed: %Rrc" ), vrc);
1256- RTVfsIoStrmRelease (hGunzipIos );
1288+ RTVfsIoStrmRelease (hDecompIos );
12571289 }
12581290 else
1259- vboxExtPackSetError (pszError, cbError, ExtPackUtil::tr (" RTZipGzipDecompressIoStream failed: %Rrc" ), vrc);
1291+ vboxExtPackSetError (pszError, cbError, ExtPackUtil::tr (" %s failed: %Rrc" ), pszDecompNm , vrc);
12601292 RTVfsIoStrmRelease (hPtIos);
12611293 }
12621294 else
0 commit comments