int sqlzma_un(struct sqlzma_un *un, struct sized_buf *src, struct sized_buf *dst) { int err, by_lzma = 1; if (un->un_lzma && is_lzma(*src->buf)) { un->un_cmbuf = src->buf; un->un_cmlen = src->sz; un->un_resbuf = dst->buf; un->un_reslen = dst->sz; /* this library is thread-safe */ err = LzmaUncompress(un); goto out; } by_lzma = 0; //#if defined(CONFIG_MIPS_BRCM) #if 1//disable zlib inflate /* The FS is compressed with LZMA for BRCM: do not use zlib */ printk("%s: ZLIB decompression is not supported\n", __func__); err = -EINVAL; #else err = zlib_inflateReset(&un->un_stream); if (unlikely(err != Z_OK)) goto out; un->un_stream.next_in = src->buf; un->un_stream.avail_in = src->sz; un->un_stream.next_out = dst->buf; un->un_stream.avail_out = dst->sz; err = zlib_inflate(&un->un_stream, Z_FINISH); if (err == Z_STREAM_END) err = 0; #endif out: if (unlikely(err)) { #ifdef __KERNEL__ WARN_ON_ONCE(1); #else char a[64] = "ZLIB "; if (by_lzma) { strcpy(a, "LZMA "); #ifdef _REENTRANT strerror_r(err, a + 5, sizeof(a) - 5); #else strncat(a, strerror(err), sizeof(a) - 5); #endif } else strncat(a, zError(err), sizeof(a) - 5); fprintf(stderr, "%s: %.*s\n", __func__, sizeof(a), a); #endif } return err; }
int sqlzma_un(struct sqlzma_un *un, struct sized_buf *src, struct sized_buf *dst) { int err, by_lzma = 0; if (un->un_lzma && is_lzma(*src->buf)) { by_lzma = 1; un->un_cmbuf = src->buf; un->un_cmlen = src->sz; un->un_resbuf = dst->buf; un->un_reslen = dst->sz; /* this library is thread-safe */ err = LzmaUncompress(un); goto out; } err = zlib_inflateReset(&un->un_stream); if (unlikely(err != Z_OK)) goto out; un->un_stream.next_in = src->buf; un->un_stream.avail_in = src->sz; un->un_stream.next_out = dst->buf; un->un_stream.avail_out = dst->sz; err = zlib_inflate(&un->un_stream, Z_FINISH); if (err == Z_STREAM_END) err = 0; out: if (err) { #ifdef __KERNEL__ WARN_ON_ONCE(1); #else char a[64] = "ZLIB "; if (by_lzma) { strcpy(a, "LZMA "); #ifdef _REENTRANT strerror_r(err, a + 5, sizeof(a) - 5); #else strncat(a, strerror(err), sizeof(a) - 5); #endif } else strncat(a, zError(err), sizeof(a) - 5); fprintf(stderr, "%s: %.*s\n", __func__, sizeof(a), a); #endif } return err; }
Array<uint8_t> decompress(RawArray<const uint8_t> compressed, const size_t uncompressed_size, event_t event) { GEODE_ASSERT(uncompressed_size<(uint64_t)1<<31); thread_time_t time(decompress_kind,event); size_t dest_size = uncompressed_size; Array<uint8_t> uncompressed = aligned_buffer<uint8_t>(CHECK_CAST_INT(dest_size)); if (!is_lzma(compressed)) { // zlib int z = uncompress((uint8_t*)uncompressed.data(),&dest_size,compressed.data(),compressed.size()); if (z!=Z_OK) THROW(IOError,"zlib failure in read_and_uncompress: %s",zlib_error(z)); } else { // lzma const uint32_t flags = LZMA_TELL_NO_CHECK | LZMA_TELL_UNSUPPORTED_CHECK; uint64_t memlimit = UINT64_MAX; size_t in_pos = 0, out_pos = 0; lzma_ret r = lzma_stream_buffer_decode(&memlimit,flags,0,compressed.data(),&in_pos,compressed.size(),uncompressed.data(),&out_pos,dest_size); if (r!=LZMA_OK) THROW(IOError,"lzma failure in read_and_uncompress: %s (%d)",lzma_error(r),r); } if (dest_size != uncompressed_size) THROW(IOError,"read_and_compress: expected uncompressed size %zu, got %zu",uncompressed_size,dest_size); return uncompressed; }