1387 strm.next_out = buf;
1388 strm.avail_out = (uInt)entry->size;
1389
1390 while (count > 0) {
1391 jint n = count > (jlong)sizeof(tmp) ? (jint)sizeof(tmp) : (jint)count;
1392 ZIP_Lock(zip);
1393 n = ZIP_Read(zip, entry, pos, tmp, n);
1394 ZIP_Unlock(zip);
1395 if (n <= 0) {
1396 if (n == 0) {
1397 *msg = "inflateFully: Unexpected end of file";
1398 }
1399 inflateEnd(&strm);
1400 return JNI_FALSE;
1401 }
1402 pos += n;
1403 count -= n;
1404 strm.next_in = (Bytef *)tmp;
1405 strm.avail_in = n;
1406 do {
1407 switch (inflate(&strm, Z_PARTIAL_FLUSH)) {
1408 case Z_OK:
1409 break;
1410 case Z_STREAM_END:
1411 if (count != 0 || strm.total_out != entry->size) {
1412 *msg = "inflateFully: Unexpected end of stream";
1413 inflateEnd(&strm);
1414 return JNI_FALSE;
1415 }
1416 break;
1417 default:
1418 break;
1419 }
1420 } while (strm.avail_in > 0);
1421 }
1422
1423 inflateEnd(&strm);
1424 return JNI_TRUE;
1425 }
1426
1427 /*
1428 * The current implementation does not support reading an entry that
1429 * has the size bigger than 2**32 bytes in ONE invocation.
1507 jboolean JNICALL
1508 ZIP_InflateFully(void *inBuf, jlong inLen, void *outBuf, jlong outLen, char **pmsg)
1509 {
1510 z_stream strm;
1511 int i = 0;
1512 memset(&strm, 0, sizeof(z_stream));
1513
1514 *pmsg = 0; /* Reset error message */
1515
1516 if (inflateInit2(&strm, MAX_WBITS) != Z_OK) {
1517 *pmsg = strm.msg;
1518 return JNI_FALSE;
1519 }
1520
1521 strm.next_out = (Bytef *) outBuf;
1522 strm.avail_out = (uInt)outLen;
1523 strm.next_in = (Bytef *) inBuf;
1524 strm.avail_in = (uInt)inLen;
1525
1526 do {
1527 switch (inflate(&strm, Z_PARTIAL_FLUSH)) {
1528 case Z_OK:
1529 break;
1530 case Z_STREAM_END:
1531 if (strm.total_out != outLen) {
1532 *pmsg = "INFLATER_inflateFully: Unexpected end of stream";
1533 inflateEnd(&strm);
1534 return JNI_FALSE;
1535 }
1536 break;
1537 case Z_DATA_ERROR:
1538 *pmsg = "INFLATER_inflateFully: Compressed data corrupted";
1539 inflateEnd(&strm);
1540 return JNI_FALSE;
1541 case Z_MEM_ERROR:
1542 *pmsg = "INFLATER_inflateFully: out of memory";
1543 inflateEnd(&strm);
1544 return JNI_FALSE;
1545 default:
1546 *pmsg = "INFLATER_inflateFully: internal error";
1547 inflateEnd(&strm);
1548 return JNI_FALSE;
|
1387 strm.next_out = buf;
1388 strm.avail_out = (uInt)entry->size;
1389
1390 while (count > 0) {
1391 jint n = count > (jlong)sizeof(tmp) ? (jint)sizeof(tmp) : (jint)count;
1392 ZIP_Lock(zip);
1393 n = ZIP_Read(zip, entry, pos, tmp, n);
1394 ZIP_Unlock(zip);
1395 if (n <= 0) {
1396 if (n == 0) {
1397 *msg = "inflateFully: Unexpected end of file";
1398 }
1399 inflateEnd(&strm);
1400 return JNI_FALSE;
1401 }
1402 pos += n;
1403 count -= n;
1404 strm.next_in = (Bytef *)tmp;
1405 strm.avail_in = n;
1406 do {
1407 switch (inflate(&strm, Z_FINISH)) {
1408 case Z_STREAM_END:
1409 if (count != 0 || strm.total_out != entry->size) {
1410 *msg = "inflateFully: Unexpected end of stream";
1411 inflateEnd(&strm);
1412 return JNI_FALSE;
1413 }
1414 break;
1415 default:
1416 break;
1417 }
1418 } while (strm.avail_in > 0);
1419 }
1420
1421 inflateEnd(&strm);
1422 return JNI_TRUE;
1423 }
1424
1425 /*
1426 * The current implementation does not support reading an entry that
1427 * has the size bigger than 2**32 bytes in ONE invocation.
1505 jboolean JNICALL
1506 ZIP_InflateFully(void *inBuf, jlong inLen, void *outBuf, jlong outLen, char **pmsg)
1507 {
1508 z_stream strm;
1509 int i = 0;
1510 memset(&strm, 0, sizeof(z_stream));
1511
1512 *pmsg = 0; /* Reset error message */
1513
1514 if (inflateInit2(&strm, MAX_WBITS) != Z_OK) {
1515 *pmsg = strm.msg;
1516 return JNI_FALSE;
1517 }
1518
1519 strm.next_out = (Bytef *) outBuf;
1520 strm.avail_out = (uInt)outLen;
1521 strm.next_in = (Bytef *) inBuf;
1522 strm.avail_in = (uInt)inLen;
1523
1524 do {
1525 switch (inflate(&strm, Z_FINISH)) {
1526 case Z_OK:
1527 case Z_BUF_ERROR:
1528 break;
1529 case Z_STREAM_END:
1530 if (strm.total_out != outLen) {
1531 *pmsg = "INFLATER_inflateFully: Unexpected end of stream";
1532 inflateEnd(&strm);
1533 return JNI_FALSE;
1534 }
1535 break;
1536 case Z_DATA_ERROR:
1537 *pmsg = "INFLATER_inflateFully: Compressed data corrupted";
1538 inflateEnd(&strm);
1539 return JNI_FALSE;
1540 case Z_MEM_ERROR:
1541 *pmsg = "INFLATER_inflateFully: out of memory";
1542 inflateEnd(&strm);
1543 return JNI_FALSE;
1544 default:
1545 *pmsg = "INFLATER_inflateFully: internal error";
1546 inflateEnd(&strm);
1547 return JNI_FALSE;
|