internal static int inflate_trees_fixed(int[] bl, int[] bd, int[][] tl, int[][] td, ZStream z) { bl[0] = fixed_bl; bd[0] = fixed_bd; tl[0] = fixed_tl; td[0] = fixed_td; return(Z_OK); }
internal static int inflate_trees_bits(int[] c, int[] bb, int[] tb, int[] hp, ZStream z) { int r; int[] hn = new int[1]; // hufts used in space int[] v = new int[19]; // work area for huft_build r = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v); if (r == Z_DATA_ERROR) { z.msg = "oversubscribed dynamic bit lengths tree"; } else if (r == Z_BUF_ERROR || bb[0] == 0) { z.msg = "incomplete dynamic bit lengths tree"; r = Z_DATA_ERROR; } return(r); }
internal static int inflate_trees_dynamic(int nl, int nd, int[] c, int[] bl, int[] bd, int[] tl, int[] td, int[] hp, ZStream z) { int r; int[] hn = new int[1]; // hufts used in space int[] v = new int[288]; // work area for huft_build // build literal/length tree r = huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v); if (r != Z_OK || bl[0] == 0) { if (r == Z_DATA_ERROR) { z.msg = "oversubscribed literal/length tree"; } else if (r != Z_MEM_ERROR) { z.msg = "incomplete literal/length tree"; r = Z_DATA_ERROR; } return(r); } // build distance tree r = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v); if (r != Z_OK || (bd[0] == 0 && nl > 257)) { if (r == Z_DATA_ERROR) { z.msg = "oversubscribed distance tree"; } else if (r == Z_BUF_ERROR) { z.msg = "incomplete distance tree"; r = Z_DATA_ERROR; } else if (r != Z_MEM_ERROR) { z.msg = "empty distance tree with lengths"; r = Z_DATA_ERROR; } return(r); } return(Z_OK); }
internal int inflate(ZStream z, int f) { int r; int b; if (z == null || z.istate == null || z.next_in == null) { return(Z_STREAM_ERROR); } f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK; r = Z_BUF_ERROR; while (true) { //System.out.println("mode: "+z.istate.mode); switch (z.istate.mode) { case METHOD: if (z.avail_in == 0) { return(r); } r = f; z.avail_in--; z.total_in++; if (((z.istate.method = z.next_in[z.next_in_index++]) & 0xf) != Z_DEFLATED) { z.istate.mode = BAD; z.msg = "unknown compression method"; z.istate.marker = 5; // can't try inflateSync break; } if ((z.istate.method >> 4) + 8 > z.istate.wbits) { z.istate.mode = BAD; z.msg = "invalid window size"; z.istate.marker = 5; // can't try inflateSync break; } z.istate.mode = FLAG; goto case FLAG; case FLAG: if (z.avail_in == 0) { return(r); } r = f; z.avail_in--; z.total_in++; b = (z.next_in[z.next_in_index++]) & 0xff; if ((((z.istate.method << 8) + b) % 31) != 0) { z.istate.mode = BAD; z.msg = "incorrect header check"; z.istate.marker = 5; // can't try inflateSync break; } if ((b & PRESET_DICT) == 0) { z.istate.mode = BLOCKS; break; } z.istate.mode = DICT4; goto case DICT4; case DICT4: if (z.avail_in == 0) { return(r); } r = f; z.avail_in--; z.total_in++; z.istate.need = ((z.next_in[z.next_in_index++] & 0xff) << 24) & unchecked ((int)0xff000000L); z.istate.mode = DICT3; goto case DICT3; case DICT3: if (z.avail_in == 0) { return(r); } r = f; z.avail_in--; z.total_in++; z.istate.need += (((z.next_in[z.next_in_index++] & 0xff) << 16) & 0xff0000L); z.istate.mode = DICT2; goto case DICT2; case DICT2: if (z.avail_in == 0) { return(r); } r = f; z.avail_in--; z.total_in++; z.istate.need += (((z.next_in[z.next_in_index++] & 0xff) << 8) & 0xff00L); z.istate.mode = DICT1; goto case DICT1; case DICT1: if (z.avail_in == 0) { return(r); } r = f; z.avail_in--; z.total_in++; z.istate.need += (z.next_in[z.next_in_index++] & 0xffL); z.adler = z.istate.need; z.istate.mode = DICT0; return(Z_NEED_DICT); case DICT0: z.istate.mode = BAD; z.msg = "need dictionary"; z.istate.marker = 0; // can try inflateSync return(Z_STREAM_ERROR); case BLOCKS: r = z.istate.blocks.proc(z, r); if (r == Z_DATA_ERROR) { z.istate.mode = BAD; z.istate.marker = 0; // can try inflateSync break; } if (r == Z_OK) { r = f; } if (r != Z_STREAM_END) { return(r); } r = f; z.istate.blocks.reset(z, z.istate.was); if (z.istate.nowrap != 0) { z.istate.mode = DONE; break; } z.istate.mode = CHECK4; goto case CHECK4; case CHECK4: if (z.avail_in == 0) { return(r); } r = f; z.avail_in--; z.total_in++; z.istate.need = ((z.next_in[z.next_in_index++] & 0xff) << 24) & unchecked ((int)0xff000000L); z.istate.mode = CHECK3; goto case CHECK3; case CHECK3: if (z.avail_in == 0) { return(r); } r = f; z.avail_in--; z.total_in++; z.istate.need += (((z.next_in[z.next_in_index++] & 0xff) << 16) & 0xff0000L); z.istate.mode = CHECK2; goto case CHECK2; case CHECK2: if (z.avail_in == 0) { return(r); } r = f; z.avail_in--; z.total_in++; z.istate.need += (((z.next_in[z.next_in_index++] & 0xff) << 8) & 0xff00L); z.istate.mode = CHECK1; goto case CHECK1; case CHECK1: if (z.avail_in == 0) { return(r); } r = f; z.avail_in--; z.total_in++; z.istate.need += (z.next_in[z.next_in_index++] & 0xffL); if (((int)(z.istate.was[0])) != ((int)(z.istate.need))) { z.istate.mode = BAD; z.msg = "incorrect data check"; z.istate.marker = 5; // can't try inflateSync break; } z.istate.mode = DONE; goto case DONE; case DONE: return(Z_STREAM_END); case BAD: return(Z_DATA_ERROR); default: return(Z_STREAM_ERROR); } } }