< prev index next >

src/java.base/share/native/libzip/zip_util.c

Print this page




1285             zip->msg = "invalid LOC header (bad signature)";
1286             return -1;
1287         }
1288         entry->pos = (- entry->pos) + LOCHDR + LOCNAM(loc) + LOCEXT(loc);
1289     }
1290     return entry->pos;
1291 }
1292 
1293 /*
1294  * Reads bytes from the specified zip entry. Assumes that the zip
1295  * file had been previously locked with ZIP_Lock(). Returns the
1296  * number of bytes read, or -1 if an error occurred. If zip->msg != 0
1297  * then a zip error occurred and zip->msg contains the error text.
1298  *
1299  * The current implementation does not support reading an entry that
1300  * has the size bigger than 2**32 bytes in ONE invocation.
1301  */
1302 jint
1303 ZIP_Read(jzfile *zip, jzentry *entry, jlong pos, void *buf, jint len)
1304 {
1305     jlong entry_size = (entry->csize != 0) ? entry->csize : entry->size;
1306     jlong start;
1307 




1308     /* Clear previous zip error */
1309     zip->msg = NULL;
1310 







1311     /* Check specified position */
1312     if (pos < 0 || pos > entry_size - 1) {
1313         zip->msg = "ZIP_Read: specified offset out of range";
1314         return -1;
1315     }
1316 
1317     /* Check specified length */
1318     if (len <= 0)
1319         return 0;
1320     if (len > entry_size - pos)
1321         len = (jint)(entry_size - pos);
1322 
1323     /* Get file offset to start reading data */
1324     start = ZIP_GetEntryDataOffset(zip, entry);
1325     if (start < 0)
1326         return -1;
1327     start += pos;
1328 
1329     if (start + len > zip->len) {
1330         zip->msg = "ZIP_Read: corrupt zip file: invalid entry size";


1423     jzentry *entry = ZIP_GetEntry(zip, name, 0);
1424     if (entry) {
1425         *sizeP = (jint)entry->size;
1426         *nameLenP = strlen(entry->name);
1427     }
1428     return entry;
1429 }
1430 
1431 /*
1432  * Reads a zip file entry into the specified byte array
1433  * When the method completes, it releases the jzentry.
1434  * Note: this is called from the separately delivered VM (hotspot/classic)
1435  * so we have to be careful to maintain the expected behaviour.
1436  */
1437 jboolean JNICALL
1438 ZIP_ReadEntry(jzfile *zip, jzentry *entry, unsigned char *buf, char *entryname)
1439 {
1440     char *msg;
1441     char tmpbuf[1024];
1442 





1443     strcpy(entryname, entry->name);
1444     if (entry->csize == 0) {
1445         /* Entry is stored */
1446         jlong pos = 0;
1447         jlong size = entry->size;
1448         while (pos < size) {
1449             jint n;
1450             jlong limit = ((((jlong) 1) << 31) - 1);
1451             jint count = (size - pos < limit) ?
1452                 /* These casts suppress a VC++ Internal Compiler Error */
1453                 (jint) (size - pos) :
1454                 (jint) limit;
1455             ZIP_Lock(zip);
1456             n = ZIP_Read(zip, entry, pos, buf, count);
1457             msg = zip->msg;
1458             ZIP_Unlock(zip);
1459             if (n == -1) {
1460                 if (msg == 0) {
1461                     getErrorString(errno, tmpbuf, sizeof(tmpbuf));
1462                     msg = tmpbuf;




1285             zip->msg = "invalid LOC header (bad signature)";
1286             return -1;
1287         }
1288         entry->pos = (- entry->pos) + LOCHDR + LOCNAM(loc) + LOCEXT(loc);
1289     }
1290     return entry->pos;
1291 }
1292 
1293 /*
1294  * Reads bytes from the specified zip entry. Assumes that the zip
1295  * file had been previously locked with ZIP_Lock(). Returns the
1296  * number of bytes read, or -1 if an error occurred. If zip->msg != 0
1297  * then a zip error occurred and zip->msg contains the error text.
1298  *
1299  * The current implementation does not support reading an entry that
1300  * has the size bigger than 2**32 bytes in ONE invocation.
1301  */
1302 jint
1303 ZIP_Read(jzfile *zip, jzentry *entry, jlong pos, void *buf, jint len)
1304 {
1305     jlong entry_size;
1306     jlong start;
1307 
1308     if (zip == 0) {
1309         return -1;
1310     }
1311 
1312     /* Clear previous zip error */
1313     zip->msg = NULL;
1314 
1315     if (entry == 0) {
1316         zip->msg = "ZIP_Read: jzentry is NULL";
1317         return -1;
1318     }
1319 
1320     entry_size = (entry->csize != 0) ? entry->csize : entry->size;
1321 
1322     /* Check specified position */
1323     if (pos < 0 || pos > entry_size - 1) {
1324         zip->msg = "ZIP_Read: specified offset out of range";
1325         return -1;
1326     }
1327 
1328     /* Check specified length */
1329     if (len <= 0)
1330         return 0;
1331     if (len > entry_size - pos)
1332         len = (jint)(entry_size - pos);
1333 
1334     /* Get file offset to start reading data */
1335     start = ZIP_GetEntryDataOffset(zip, entry);
1336     if (start < 0)
1337         return -1;
1338     start += pos;
1339 
1340     if (start + len > zip->len) {
1341         zip->msg = "ZIP_Read: corrupt zip file: invalid entry size";


1434     jzentry *entry = ZIP_GetEntry(zip, name, 0);
1435     if (entry) {
1436         *sizeP = (jint)entry->size;
1437         *nameLenP = strlen(entry->name);
1438     }
1439     return entry;
1440 }
1441 
1442 /*
1443  * Reads a zip file entry into the specified byte array
1444  * When the method completes, it releases the jzentry.
1445  * Note: this is called from the separately delivered VM (hotspot/classic)
1446  * so we have to be careful to maintain the expected behaviour.
1447  */
1448 jboolean JNICALL
1449 ZIP_ReadEntry(jzfile *zip, jzentry *entry, unsigned char *buf, char *entryname)
1450 {
1451     char *msg;
1452     char tmpbuf[1024];
1453 
1454     if (entry == 0) {
1455         jio_fprintf(stderr, "jzentry was invalid");
1456         return JNI_FALSE;
1457     }
1458 
1459     strcpy(entryname, entry->name);
1460     if (entry->csize == 0) {
1461         /* Entry is stored */
1462         jlong pos = 0;
1463         jlong size = entry->size;
1464         while (pos < size) {
1465             jint n;
1466             jlong limit = ((((jlong) 1) << 31) - 1);
1467             jint count = (size - pos < limit) ?
1468                 /* These casts suppress a VC++ Internal Compiler Error */
1469                 (jint) (size - pos) :
1470                 (jint) limit;
1471             ZIP_Lock(zip);
1472             n = ZIP_Read(zip, entry, pos, buf, count);
1473             msg = zip->msg;
1474             ZIP_Unlock(zip);
1475             if (n == -1) {
1476                 if (msg == 0) {
1477                     getErrorString(errno, tmpbuf, sizeof(tmpbuf));
1478                     msg = tmpbuf;


< prev index next >