diff options
| author | Petr Mrázek <peterix@gmail.com> | 2013-09-29 21:11:30 +0200 |
|---|---|---|
| committer | Petr Mrázek <peterix@gmail.com> | 2013-09-29 21:11:30 +0200 |
| commit | 604162acdf5283a9759c1b3ce9e90887a6599ce7 (patch) | |
| tree | 06dc5f9ce330afb03922f822b9203169e17576e6 /depends | |
| parent | d267d86f6e24c4f947c30c1a3642d57b82f8addd (diff) | |
| download | PrismLauncher-604162acdf5283a9759c1b3ce9e90887a6599ce7.tar.gz PrismLauncher-604162acdf5283a9759c1b3ce9e90887a6599ce7.tar.bz2 PrismLauncher-604162acdf5283a9759c1b3ce9e90887a6599ce7.zip | |
Turn pack200 into an actual library
Diffstat (limited to 'depends')
| -rw-r--r-- | depends/pack200/CMakeLists.txt | 10 | ||||
| -rw-r--r-- | depends/pack200/anti200.cpp | 28 | ||||
| -rw-r--r-- | depends/pack200/include/unpack200.h | 38 | ||||
| -rw-r--r-- | depends/pack200/src/bands.cpp | 36 | ||||
| -rw-r--r-- | depends/pack200/src/bands.h | 9 | ||||
| -rw-r--r-- | depends/pack200/src/bytes.cpp | 4 | ||||
| -rw-r--r-- | depends/pack200/src/bytes.h | 2 | ||||
| -rw-r--r-- | depends/pack200/src/coding.cpp | 125 | ||||
| -rw-r--r-- | depends/pack200/src/coding.h | 29 | ||||
| -rw-r--r-- | depends/pack200/src/constants.h | 2 | ||||
| -rw-r--r-- | depends/pack200/src/defines.h | 75 | ||||
| -rw-r--r-- | depends/pack200/src/main.cpp | 489 | ||||
| -rw-r--r-- | depends/pack200/src/unpack.cpp | 670 | ||||
| -rw-r--r-- | depends/pack200/src/unpack.h | 114 | ||||
| -rw-r--r-- | depends/pack200/src/unpack200.cpp | 172 | ||||
| -rw-r--r-- | depends/pack200/src/utils.cpp | 28 | ||||
| -rw-r--r-- | depends/pack200/src/utils.h | 9 | ||||
| -rw-r--r-- | depends/pack200/src/zip.cpp | 56 | ||||
| -rw-r--r-- | depends/pack200/src/zip.h | 28 | ||||
| -rw-r--r-- | depends/xz-embedded/CMakeLists.txt | 11 |
20 files changed, 583 insertions, 1352 deletions
diff --git a/depends/pack200/CMakeLists.txt b/depends/pack200/CMakeLists.txt index 79c78f80..657e303c 100644 --- a/depends/pack200/CMakeLists.txt +++ b/depends/pack200/CMakeLists.txt @@ -19,6 +19,7 @@ ELSE(UNIX) ENDIF(UNIX) SET(PACK200_SRC +include/unpack200.h src/bands.cpp src/bands.h src/bytes.cpp @@ -27,7 +28,7 @@ src/coding.cpp src/coding.h src/constants.h src/defines.h -src/main.cpp +src/unpack200.cpp src/unpack.cpp src/unpack.h src/utils.cpp @@ -36,7 +37,9 @@ src/zip.cpp src/zip.h ) -add_executable(unpack200 ${PACK200_SRC}) +include_directories(include) + +add_library(unpack200 STATIC ${PACK200_SRC}) IF(UNIX) target_link_libraries(unpack200 ${ZLIB_LIBRARIES}) @@ -44,3 +47,6 @@ ELSE() # zlib is part of Qt on windows. use it. QT5_USE_MODULES(unpack200 Core) ENDIF() + +add_executable(anti200 anti200.cpp) +target_link_libraries(anti200 unpack200) diff --git a/depends/pack200/anti200.cpp b/depends/pack200/anti200.cpp new file mode 100644 index 00000000..3dfdb5dc --- /dev/null +++ b/depends/pack200/anti200.cpp @@ -0,0 +1,28 @@ +/* + * This is trivial. Do what thou wilt with it. Public domain. + */ + +#include <stdexcept> +#include <iostream> +#include "unpack200.h" + +int main(int argc, char **argv) +{ + if (argc == 3) + { + try + { + unpack_200(argv[1], argv[2]); + } + catch (std::runtime_error &e) + { + std::cerr << "Bad things happened: " << e.what() << std::endl; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; + } + else + std::cerr << "Simple pack200 unpacker!" << std::endl << "Run like this:" << std::endl + << " " << argv[0] << " input.jar.lzma output.jar" << std::endl; + return EXIT_FAILURE; +} diff --git a/depends/pack200/include/unpack200.h b/depends/pack200/include/unpack200.h index 8d1c8b69..bcee8009 100644 --- a/depends/pack200/include/unpack200.h +++ b/depends/pack200/include/unpack200.h @@ -1 +1,37 @@ - +/* + * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#pragma once +#include <string> + +/** + * @brief Unpack a PACK200 file + * + * @param input_path Path to the input file in PACK200 format. System native string encoding. + * @param output_path Path to the output file in PACK200 format. System native string encoding. + * @return void + * @throw std::runtime_error for any error encountered + */ +void unpack_200(std::string input_path, std::string output_path); diff --git a/depends/pack200/src/bands.cpp b/depends/pack200/src/bands.cpp index 6b4e8971..1c10b35b 100644 --- a/depends/pack200/src/bands.cpp +++ b/depends/pack200/src/bands.cpp @@ -34,6 +34,7 @@ #include <stdlib.h> #include <stdarg.h> #include <assert.h> +#include <stdint.h> #include "defines.h" #include "bytes.h" @@ -44,18 +45,8 @@ #include "constants.h" #include "unpack.h" -inline void band::abort(const char *msg) -{ - u->abort(msg); -} -inline bool band::aborting() -{ - return u->aborting(); -} - void band::readData(int expectedLength) { - CHECK; assert(expectedLength >= 0); assert(vs[0].cmk == cmk_ERROR); if (expectedLength != 0) @@ -82,7 +73,7 @@ void band::readData(int expectedLength) // Make a conservatively generous estimate of band size in bytes. // Assume B == 5 everywhere. // Assume awkward pop with all {U} values (2*5 per value) - jlong generous = (jlong)length * (B_MAX * 3 + 1) + C_SLOP; + int64_t generous = (int64_t)length * (B_MAX * 3 + 1) + C_SLOP; u->ensure_input(generous); } @@ -102,7 +93,6 @@ void band::readData(int expectedLength) assert(!valc->isMalloc); } xvs.init(u->rp, u->rplimit, valc); - CHECK; int X = xvs.getInt(); if (valc->S() != 0) { @@ -133,7 +123,6 @@ void band::readData(int expectedLength) byte XB_byte = (byte)XB; byte *XB_ptr = &XB_byte; cm.init(u->rp, u->rplimit, XB_ptr, 0, defc, length, nullptr); - CHECK; } else { @@ -162,7 +151,6 @@ void band::setIndexByTag(byte tag) entry *band::getRefCommon(cpindex *ix_, bool nullOKwithCaller) { - CHECK_0; assert(ix_->ixTag == ixTag || (ixTag == CONSTANT_Literal && ix_->ixTag >= CONSTANT_Integer && ix_->ixTag <= CONSTANT_String)); @@ -171,27 +159,26 @@ entry *band::getRefCommon(cpindex *ix_, bool nullOKwithCaller) // But nullOKwithCaller means caller is willing to tolerate a nullptr. entry *ref = ix_->get(n); if (ref == nullptr && !(nullOKwithCaller && n == -1)) - abort(n == -1 ? "nullptr ref" : "bad ref"); + unpack_abort(n == -1 ? "nullptr ref" : "bad ref"); return ref; } -jlong band::getLong(band &lo_band, bool have_hi) +int64_t band::getLong(band &lo_band, bool have_hi) { band &hi_band = (*this); assert(lo_band.bn == hi_band.bn + 1); - uint lo = lo_band.getInt(); + uint32_t lo = lo_band.getInt(); if (!have_hi) { assert(hi_band.length == 0); return makeLong(0, lo); } - uint hi = hi_band.getInt(); + uint32_t hi = hi_band.getInt(); return makeLong(hi, lo); } int band::getIntTotal() { - CHECK_0; if (length == 0) return 0; if (total_memo > 0) @@ -201,8 +188,7 @@ int band::getIntTotal() // and that the partial sums never overflow (wrap negative) if (total < 0) { - abort("overflow detected"); - return 0; + unpack_abort("overflow detected"); } for (int k = length - 1; k > 0; k--) { @@ -210,8 +196,7 @@ int band::getIntTotal() total += vs[0].getInt(); if (total < prev_total) { - abort("overflow detected"); - return 0; + unpack_abort("overflow detected"); } } rewind(); @@ -221,7 +206,6 @@ int band::getIntTotal() int band::getIntCount(int tag) { - CHECK_0; if (length == 0) return 0; if (tag >= HIST0_MIN && tag <= HIST0_MAX) @@ -230,7 +214,6 @@ int band::getIntCount(int tag) { // Lazily calculate an approximate histogram. hist0 = U_NEW(int, (HIST0_MAX - HIST0_MIN) + 1); - CHECK_0; for (int k = length; k > 0; k--) { int x = vs[0].getInt(); @@ -404,7 +387,6 @@ const band_init all_band_inits[] = BAND_INIT(file_modtime, DELTA5_spec, 0), BAND_INIT(file_options, UNSIGNED5_spec, 0), // BAND_INIT(file_bits, BYTE1_spec, 0), {0, 0}}; -#define NUM_BAND_INITS (sizeof(all_band_inits) / sizeof(all_band_inits[0])) band *band::makeBands(unpacker *u) { @@ -434,7 +416,7 @@ void band::initIndexes(unpacker *u) for (int i = 0; i < BAND_LIMIT; i++) { band *scan = &tmp_all_bands[i]; - uint tag = scan->ixTag; // Cf. #define INDEX(tag) above + uint32_t tag = scan->ixTag; // Cf. #define INDEX(tag) above if (tag != 0 && tag != CONSTANT_Literal && (tag & SUBINDEX_BIT) == 0) { scan->setIndex(u->cp.getIndex(tag)); diff --git a/depends/pack200/src/bands.h b/depends/pack200/src/bands.h index 3f944481..a56cd7d5 100644 --- a/depends/pack200/src/bands.h +++ b/depends/pack200/src/bands.h @@ -150,11 +150,11 @@ struct band return getRefCommon(ix2, true); } entry *getRefCommon(cpindex *ix, bool nullOK); - jlong getLong(band &lo_band, bool have_hi); + int64_t getLong(band &lo_band, bool have_hi); - static jlong makeLong(uint hi, uint lo) + static int64_t makeLong(uint32_t hi, uint32_t lo) { - return ((julong)hi << 32) + (((julong)lo << 32) >> 32); + return ((uint64_t)hi << 32) + (((uint64_t)lo << 32) >> 32); } int getIntTotal(); @@ -162,9 +162,6 @@ struct band static band *makeBands(unpacker *u); static void initIndexes(unpacker *u); - - void abort(const char *msg = nullptr); //{ u->abort(msg); } - bool aborting(); //{ return u->aborting(); } }; extern band all_bands[]; diff --git a/depends/pack200/src/bytes.cpp b/depends/pack200/src/bytes.cpp index b82a987a..d3808afa 100644 --- a/depends/pack200/src/bytes.cpp +++ b/depends/pack200/src/bytes.cpp @@ -27,6 +27,7 @@ #include <stdlib.h> #include <string.h> #include <assert.h> +#include <stdint.h> #include "defines.h" #include "bytes.h" #include "utils.h" @@ -114,7 +115,7 @@ int bytes::compareTo(bytes &other) void bytes::saveFrom(const void *ptr_, size_t len_) { malloc(len_); - // Save as much as possible. (Helps unpacker::abort.) + // Save as much as possible. if (len_ > len) { assert(ptr == dummy); // error recovery @@ -161,7 +162,6 @@ byte *fillbytes::grow(size_t s) allocated = b.len; if (allocated != maxlen) { - assert(unpack_aborting()); b.len = nlen - s; // back up return dummy; // scribble during error recov. } diff --git a/depends/pack200/src/bytes.h b/depends/pack200/src/bytes.h index 3926f9f2..2e4a9daf 100644 --- a/depends/pack200/src/bytes.h +++ b/depends/pack200/src/bytes.h @@ -161,7 +161,7 @@ struct fillbytes b.len = 0; } int8_t *grow(size_t s); // grow so that limit() += s - int getByte(uint i) + int getByte(uint32_t i) { return *loc(i) & 0xFF; } diff --git a/depends/pack200/src/coding.cpp b/depends/pack200/src/coding.cpp index 32977e05..226ba458 100644 --- a/depends/pack200/src/coding.cpp +++ b/depends/pack200/src/coding.cpp @@ -32,6 +32,7 @@ #include <stdlib.h> #include <stdarg.h> #include <assert.h> +#include <stdint.h> #include "defines.h" #include "bytes.h" @@ -53,12 +54,12 @@ extern coding basic_codings[]; #define IS_NEG_CODE(S, codeVal) ((((int)(codeVal) + 1) & ((1 << S) - 1)) == 0) -#define DECODE_SIGN_S1(ux) (((uint)(ux) >> 1) ^ -((int)(ux) & 1)) +#define DECODE_SIGN_S1(ux) (((uint32_t)(ux) >> 1) ^ -((int)(ux) & 1)) -static int decode_sign(int S, uint ux) +static int decode_sign(int S, uint32_t ux) { // == Coding.decodeSign32 assert(S > 0); - uint sigbits = (ux >> S); + uint32_t sigbits = (ux >> S); if (IS_NEG_CODE(S, ux)) return (int)(~sigbits); else @@ -90,9 +91,9 @@ coding *coding::init() return nullptr; // no 5-byte fixed-size coding // first compute the range of the coding, in 64 bits - jlong range = 0; + int64_t range = 0; { - jlong H_i = 1; + int64_t H_i = 1; for (int i = 0; i < B; i++) { range += H_i; @@ -106,7 +107,7 @@ coding *coding::init() int this_umax; // now, compute min and max - if (range >= ((jlong)1 << 32)) + if (range >= ((int64_t)1 << 32)) { this_umax = INT_MAX_VALUE; this->umin = INT_MIN_VALUE; @@ -121,13 +122,13 @@ coding *coding::init() if (S != 0 && range != 0) { int Smask = (1 << S) - 1; - jlong maxPosCode = range - 1; - jlong maxNegCode = range - 1; + int64_t maxPosCode = range - 1; + int64_t maxNegCode = range - 1; while (IS_NEG_CODE(S, maxPosCode)) --maxPosCode; while (!IS_NEG_CODE(S, maxNegCode)) --maxNegCode; - int maxPos = decode_sign(S, (uint)maxPosCode); + int maxPos = decode_sign(S, (uint32_t)maxPosCode); if (maxPos < 0) this->max = INT_MAX_VALUE; // 32-bit wraparound else @@ -135,7 +136,7 @@ coding *coding::init() if (maxNegCode < 0) this->min = 0; // No negative codings at all. else - this->min = decode_sign(S, (uint)maxNegCode); + this->min = decode_sign(S, (uint32_t)maxNegCode); } } @@ -163,7 +164,8 @@ coding *coding::findBySpec(int spec) break; } coding *ptr = NEW(coding, 1); - CHECK_NULL_0(ptr); + if (!ptr) + return nullptr; coding *c = ptr->initFrom(spec); if (c == nullptr) { @@ -207,25 +209,25 @@ void coding_method::reset(value_stream *state) } } -uint coding::parse(byte *&rp, int B, int H) +uint32_t coding::parse(byte *&rp, int B, int H) { int L = 256 - H; byte *ptr = rp; // hand peel the i==0 part of the loop: - uint b_i = *ptr++ & 0xFF; - if (B == 1 || b_i < (uint)L) + uint32_t b_i = *ptr++ & 0xFF; + if (B == 1 || b_i < (uint32_t)L) { rp = ptr; return b_i; } - uint sum = b_i; - uint H_i = H; + uint32_t sum = b_i; + uint32_t H_i = H; assert(B <= B_MAX); for (int i = 2; i <= B_MAX; i++) { // easy for compilers to unroll if desired b_i = *ptr++ & 0xFF; sum += b_i * H_i; - if (i == B || b_i < (uint)L) + if (i == B || b_i < (uint32_t)L) { rp = ptr; return sum; @@ -236,26 +238,26 @@ uint coding::parse(byte *&rp, int B, int H) return 0; } -uint coding::parse_lgH(byte *&rp, int B, int H, int lgH) +uint32_t coding::parse_lgH(byte *&rp, int B, int H, int lgH) { assert(H == (1 << lgH)); int L = 256 - (1 << lgH); byte *ptr = rp; // hand peel the i==0 part of the loop: - uint b_i = *ptr++ & 0xFF; - if (B == 1 || b_i < (uint)L) + uint32_t b_i = *ptr++ & 0xFF; + if (B == 1 || b_i < (uint32_t)L) { rp = ptr; return b_i; } - uint sum = b_i; - uint lg_H_i = lgH; + uint32_t sum = b_i; + uint32_t lg_H_i = lgH; assert(B <= B_MAX); for (int i = 2; i <= B_MAX; i++) { // easy for compilers to unroll if desired b_i = *ptr++ & 0xFF; sum += b_i << lg_H_i; - if (i == B || b_i < (uint)L) + if (i == B || b_i < (uint32_t)L) { rp = ptr; return sum; @@ -272,7 +274,7 @@ void coding::parseMultiple(byte *&rp, int N, byte *limit, int B, int H) { if (N < 0) { - abort("bad value count"); + unpack_abort("bad value count"); return; } byte *ptr = rp; @@ -281,7 +283,7 @@ void coding::parseMultiple(byte *&rp, int N, byte *limit, int B, int H) size_t len = (size_t)N * B; if (len / B != (size_t)N || ptr + len > limit) { - abort(ERB); + unpack_abort(ERB); return; } rp = ptr + len; @@ -312,7 +314,7 @@ void coding::parseMultiple(byte *&rp, int N, byte *limit, int B, int H) // do an error check here if (ptr > limit) { - abort(ERB); + unpack_abort(ERB); return; } } @@ -401,12 +403,12 @@ void value_stream::setCoding(coding *defc) } } -static int getPopValue(value_stream *self, uint uval) +static int getPopValue(value_stream *self, uint32_t uval) { if (uval > 0) { // note that the initial parse performed a range check - assert(uval <= (uint)self->cm->fVlength); + assert(uval <= (uint32_t)self->cm->fVlength); return self->cm->fValues[uval - 1]; } else @@ -422,7 +424,7 @@ int coding::sumInUnsignedRange(int x, int y) int range = (int)(umax + 1); assert(range > 0); x += y; - if (x != (int)((jlong)(x - y) + (jlong)y)) + if (x != (int)((int64_t)(x - y) + (int64_t)y)) { // 32-bit overflow interferes with range reduction. // Back off from the overflow by adding a multiple of range: @@ -461,9 +463,9 @@ int coding::sumInUnsignedRange(int x, int y) return x; } -static int getDeltaValue(value_stream *self, uint uval, bool isSubrange) +static int getDeltaValue(value_stream *self, uint32_t uval, bool isSubrange) { - assert((uint)(self->c.isSubrange) == (uint)isSubrange); + assert((uint32_t)(self->c.isSubrange) == (uint32_t)isSubrange); assert(self->c.isSubrange | self->c.isFullRange); if (isSubrange) return self->sum = self->c.sumInUnsignedRange(self->sum, (int)uval); @@ -499,7 +501,7 @@ int value_stream::getInt() } CODING_PRIVATE(c.spec); - uint uval; + uint32_t uval; enum { B5 = 5, @@ -546,19 +548,19 @@ int value_stream::getInt() assert(D == 1); uval = coding::parse(rp, B, H); if (S != 0) - uval = (uint)decode_sign(S, uval); + uval = (uint32_t)decode_sign(S, uval); return getDeltaValue(this, uval, (bool)c.isSubrange); case cmk_BHS1D1full: assert(S == 1 && D == 1 && c.isFullRange); uval = coding::parse(rp, B, H); - uval = (uint)DECODE_SIGN_S1(uval); + uval = (uint32_t)DECODE_SIGN_S1(uval); return getDeltaValue(this, uval, false); case cmk_BHS1D1sub: assert(S == 1 && D == 1 && c.isSubrange); uval = coding::parse(rp, B, H); - uval = (uint)DECODE_SIGN_S1(uval); + uval = (uint32_t)DECODE_SIGN_S1(uval); return getDeltaValue(this, uval, true); case cmk_DELTA5: @@ -583,7 +585,7 @@ int value_stream::getInt() uval = coding::parse(rp, B, H); if (S != 0) { - uval = (uint)decode_sign(S, uval); + uval = (uint32_t)decode_sign(S, uval); } if (D != 0) { @@ -592,7 +594,7 @@ int value_stream::getInt() sum = c.sumInUnsignedRange(sum, (int)uval); else sum += (int)uval; - uval = (uint)sum; + uval = (uint32_t)sum; } return getPopValue(this, uval); @@ -616,8 +618,8 @@ int value_stream::getInt() static int moreCentral(int x, int y) { // used to find end of Pop.{F} // Suggested implementation from the Pack200 specification: - uint kx = (x >> 31) ^ (x << 1); - uint ky = (y >> 31) ^ (y << 1); + uint32_t kx = (x >> 31) ^ (x << 1); + uint32_t ky = (y >> 31) ^ (y << 1); return (kx < ky ? x : y); } // static maybe_inline @@ -680,7 +682,7 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m to_free = foundc; // findBySpec may dynamically allocate if (foundc == nullptr) { - abort("illegal arb. coding"); + unpack_abort("illegal arbitrary coding"); return; } // and fall through @@ -699,13 +701,11 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m int N2 = (N >= 0) ? N - K : N; if (N == 0 || (N2 <= 0 && N2 != N)) { - abort("illegal run encoding"); - return; + unpack_abort("illegal run encoding"); } if ((mode & DISABLE_RUN) != 0) { - abort("illegal nested run encoding"); - return; + unpack_abort("illegal nested run encoding"); } // & Enc{ ACode } if ADef=0 (ABDef != 1) @@ -719,11 +719,11 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m { this->init(band_rp, band_limit, meta_rp, disRun, defc, K, valueSink); } - CHECK; // & Enc{ BCode } if BDef=0 (ABDef != 2) coding_method *tail = U_NEW(coding_method, 1); - CHECK_NULL(tail); + if (!tail) + return; tail->u = u; // The 'run' codings may be nested indirectly via 'pop' codings. @@ -764,13 +764,11 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m int TH = (256 - TL); if (N <= 0) { - abort("illegal pop encoding"); - return; + unpack_abort("illegal pop encoding"); } if ((mode & DISABLE_POP) != 0) { - abort("illegal nested pop encoding"); - return; + unpack_abort("illegal nested pop encoding"); } // No indirect nesting of 'pop', but 'run' is OK. @@ -796,7 +794,6 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m fValues = (u->saveTo(fvbuf, fValueSink.b), (int *)fvbuf.ptr); fVlength = fValueSink.length(); // i.e., the parameter K fValueSink.free(); - CHECK; // Skip the first {F} run in all subsequent passes. // The next call to this->init(...) will set vs0.rp to point after the {F}. @@ -812,12 +809,12 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m break; // found it tcode->free(); tcode = coding::findBySpec(B, TH); - CHECK_NULL(tcode); + if (!tcode) + return; } if (!(fVlength <= tcode->umax)) { - abort("pop.L value too small"); - return; + unpack_abort("pop.L value too small"); } this->init(band_rp, band_limit, NO_META, disPop, tcode, N, nullptr); tcode->free(); @@ -826,7 +823,6 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m { this->init(band_rp, band_limit, meta_rp, disPop, defc, N, nullptr); } - CHECK; // Count the number of zero tokens right now. // Also verify that they are in bounds. @@ -834,13 +830,12 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m value_stream vs = vs0; for (int i = 0; i < N; i++) { - uint val = vs.getInt(); + uint32_t val = vs.getInt(); if (val == 0) UN += 1; - if (!(val <= (uint)fVlength)) + if (!(val <= (uint32_t)fVlength)) { - abort("pop token out of range"); - return; + unpack_abort("pop token out of range"); } } vs.done(); @@ -849,7 +844,8 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m if (UN != 0) { uValues = U_NEW(coding_method, 1); - CHECK_NULL(uValues); + if (uValues == nullptr) + return; uValues->u = u; if (UDef != 0) { @@ -867,7 +863,7 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m int uop = (*meta_rp++ & 0xFF); if (uop > _meta_canon_max) // %%% Spec. requires the more strict (uop != _meta_default). - abort("bad meta-coding for empty pop/U"); + unpack_abort("bad meta-coding for empty pop/U"); } } @@ -901,8 +897,7 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m } else { - abort("bad meta-coding"); - return; + unpack_abort("bad meta-coding"); } // Common code here skips a series of values with one coding. @@ -926,7 +921,7 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m coding &c = vs0.c; CODING_PRIVATE(c.spec); // assert sane N - assert((uint)N < INT_MAX_VALUE || N == POP_FAVORED_N); + assert((uint32_t)N < INT_MAX_VALUE || N == POP_FAVORED_N); // Look at the values, or at least skip over them quickly. if (valueSink == nullptr) @@ -970,14 +965,12 @@ void coding_method::init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int m if (valueSink->length() > 0 && (val == last || val == min)) //|| val == min2 break; valueSink->add(val); - CHECK; last = val; min = moreCentral(min, last); // min2 = moreCentral2(min2, last, min); } band_rp = vs.rp; } - CHECK; // Get an accurate upper limit now. vs0.rplimit = band_rp; diff --git a/depends/pack200/src/coding.h b/depends/pack200/src/coding.h index 5f017b9e..f9bd6ca2 100644 --- a/depends/pack200/src/coding.h +++ b/depends/pack200/src/coding.h @@ -84,11 +84,11 @@ struct coding static coding *findBySpec(int B, int H, int S = 0, int D = 0); static coding *findByIndex(int irregularCodingIndex); - static uint parse(byte *&rp, int B, int H); - static uint parse_lgH(byte *&rp, int B, int H, int lgH); + static uint32_t parse(byte *&rp, int B, int H); + static uint32_t parse_lgH(byte *&rp, int B, int H, int lgH); static void parseMultiple(byte *&rp, int N, byte *limit, int B, int H); - uint parse(byte *&rp) + uint32_t parse(byte *&rp) { return parse(rp, CODING_B(spec), CODING_H(spec)); } @@ -116,12 +116,6 @@ struct coding } void free(); // free self if isMalloc - - // error handling - static void abort(const char *msg = nullptr) - { - unpack_abort(msg); - } }; enum coding_method_kind @@ -224,10 +218,6 @@ struct value_stream return this + 1; } bool hasHelper(); - - // error handling - // inline void abort(const char* msg); - // inline void aborting(); }; struct coding_method @@ -254,17 +244,4 @@ struct coding_method // The value sink is used to collect output values, when desired. void init(byte *&band_rp, byte *band_limit, byte *&meta_rp, int mode, coding *defc, int N, intlist *valueSink); - - // error handling - void abort(const char *msg) - { - unpack_abort(msg, u); - } - bool aborting() - { - return unpack_aborting(u); - } }; - -// inline void value_stream::abort(const char* msg) { cm->abort(msg); } -// inline void value_stream::aborting() { cm->aborting(); } diff --git a/depends/pack200/src/constants.h b/depends/pack200/src/constants.h index aeb3335d..2cc14b7d 100644 --- a/depends/pack200/src/constants.h +++ b/depends/pack200/src/constants.h @@ -51,7 +51,7 @@ // magic number for gzip streams (for processing pack200-gzip data) #define GZIP_MAGIC 0x1F8B0800 -#define GZIP_MAGIC_MASK 0xFFFFFF00 // last byte is variable "flg" field +#define GZIP_MAGIC_MASK 0xFFFFFF00 // last \bchar\b is variable "flg" field enum { diff --git a/depends/pack200/src/defines.h b/depends/pack200/src/defines.h index 63abae0a..cfe5fc28 100644 --- a/depends/pack200/src/defines.h +++ b/depends/pack200/src/defines.h @@ -32,39 +32,22 @@ #include <unistd.h> #endif -#ifndef FULL -#define FULL 1 /* Adds <500 bytes to the zipped final product. */ -#endif - -#if FULL // define this if you want debugging and/or compile-time attributes -#define IF_FULL(x) x -#else -#define IF_FULL(x) /*x*/ -#endif - // Error messages that we have -#define ERROR_ENOMEM "Native allocation failed" +#define ERROR_ENOMEM "Memory allocation failed" #define ERROR_FORMAT "Corrupted pack file" #define ERROR_RESOURCE "Cannot extract resource file" #define ERROR_OVERFLOW "Internal buffer overflow" #define ERROR_INTERNAL "Internal error" -#define LOGFILE_STDOUT "-" -#define LOGFILE_STDERR "" - #define lengthof(array) (sizeof(array) / sizeof(array[0])) #define NEW(T, n) (T *) must_malloc((int)(scale_size(n, sizeof(T)))) #define U_NEW(T, n) (T *) u->alloc(scale_size(n, sizeof(T))) #define T_NEW(T, n) (T *) u->temp_alloc(scale_size(n, sizeof(T))) -// bytes and byte arrays - -typedef unsigned int uint; +typedef signed char byte; #ifdef _MSC_VER -typedef LONGLONG jlong; -typedef DWORDLONG julong; #define MKDIR(dir) mkdir(dir) #define getpid() _getpid() #define PATH_MAX MAX_PATH @@ -73,64 +56,10 @@ typedef DWORDLONG julong; #define tempname _tempname #define sleep Sleep #else -typedef signed char byte; -#ifdef _LP64 -typedef long jlong; -typedef long unsigned julong; -#else -typedef long long jlong; -typedef long long unsigned julong; -#endif #define MKDIR(dir) mkdir(dir, 0777); #endif /* Must cast to void *, then size_t, then int. */ #define ptrlowbits(x) ((int)(size_t)(void *)(x)) -/* Back and forth from jlong to pointer */ -#define ptr2jlong(x) ((jlong)(size_t)(void *)(x)) -#define jlong2ptr(x) ((void *)(size_t)(x)) - -// Keys used by Java: -#define UNPACK_DEFLATE_HINT "unpack.deflate.hint" - -#define COM_PREFIX "com.sun.java.util.jar.pack." -#define UNPACK_MODIFICATION_TIME COM_PREFIX "unpack.modification.time" -#define DEBUG_VERBOSE COM_PREFIX "verbose" - -#define ZIP_ARCHIVE_MARKER_COMMENT "PACK200" - -// The following are not known to the Java classes: -#define UNPACK_REMOVE_PACKFILE COM_PREFIX "unpack.remove.packfile" - -// Called from unpacker layers -#define _CHECK_DO(t, x) \ - { \ - if (t) |
