static int wt_snappy_decompress(WT_COMPRESSOR *compressor, WT_SESSION *session, uint8_t *src, size_t src_len, uint8_t *dst, size_t dst_len, size_t *result_lenp) { snappy_status snret; size_t snaplen; __UNUSED(compressor); /* retrieve the saved length */ snaplen = *(size_t *)src; if (snaplen + sizeof(size_t) > src_len) { wiredtiger_err_printf( session, "wt_snappy_decompress: stored size exceeds buffer size"); return (WT_ERROR); } /* dst_len is an input and an output arg. */ snret = snappy_uncompress( (char *)src + sizeof(size_t), snaplen, (char *)dst, &dst_len); if (snret == SNAPPY_OK) { *result_lenp = dst_len; return (0); } return (wt_snappy_error(session, "snappy_decompress", snret)); }
/* * wt_snappy_decompress -- * WiredTiger snappy decompression. */ static int wt_snappy_decompress(WT_COMPRESSOR *compressor, WT_SESSION *session, uint8_t *src, size_t src_len, uint8_t *dst, size_t dst_len, size_t *result_lenp) { WT_EXTENSION_API *wt_api; snappy_status snret; size_t snaplen; wt_api = ((SNAPPY_COMPRESSOR *)compressor)->wt_api; /* retrieve the saved length */ snaplen = *(size_t *)src; if (snaplen + sizeof(size_t) > src_len) { (void)wt_api->err_printf(wt_api, session, "wt_snappy_decompress: stored size exceeds buffer size"); return (WT_ERROR); } /* dst_len is an input and an output arg. */ snret = snappy_uncompress( (char *)src + sizeof(size_t), snaplen, (char *)dst, &dst_len); if (snret == SNAPPY_OK) { *result_lenp = dst_len; return (0); } return ( wt_snappy_error(compressor, session, "snappy_decompress", snret)); }
static int wt_snappy_compress(WT_COMPRESSOR *compressor, WT_SESSION *session, uint8_t *src, size_t src_len, uint8_t *dst, size_t dst_len, size_t *result_lenp, int *compression_failed) { snappy_status snret; size_t snaplen; char *snapbuf; __UNUSED(compressor); /* * dst_len was computed in wt_snappy_pre_size, so we know it's big * enough. Skip past the space we'll use to store the final count * of compressed bytes. */ snaplen = dst_len - sizeof(size_t); snapbuf = (char *)dst + sizeof(size_t); /* snaplen is an input and an output arg. */ snret = snappy_compress((char *)src, src_len, snapbuf, &snaplen); if (snret == SNAPPY_OK) { /* * On decompression, snappy requires the exact compressed byte * count (the current value of snaplen). WiredTiger does not * preserve that value, so save snaplen at the beginning of the * destination buffer. */ if (snaplen + sizeof(size_t) < src_len) { *(size_t *)dst = snaplen; *result_lenp = snaplen + sizeof(size_t); *compression_failed = 0; } else /* The compressor failed to produce a smaller result. */ *compression_failed = 1; return (0); } return (wt_snappy_error(session, "snappy_compress", snret)); }