Debian Codegraph @

storage/innobase/include/dict0sdi-decompress.h

raw
1 /*****************************************************************************
2
3 Copyright (c) 2017, 2026, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8
9 This program is designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20 for more details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26 *****************************************************************************/
27
28 #ifndef DICT_SDI_DECOMPRESS_H
29 #define DICT_SDI_DECOMPRESS_H
30
31 #include <zlib.h>
32
33 /** Decompress SDI record */
34 class Sdi_Decompressor {
35 public:
36 Sdi_Decompressor(byte *uncomp_sdi, uint32_t uncomp_len, byte *comp_sdi,
37 uint32_t comp_len)
38 : m_uncomp_sdi(uncomp_sdi),
39 m_uncomp_len(uncomp_len),
40 m_comp_sdi(comp_sdi),
41 m_comp_len(comp_len) {
42 ut_ad(m_uncomp_sdi != nullptr);
43 ut_ad(m_comp_sdi != nullptr);
44 }
45
46 ~Sdi_Decompressor() = default;
47
48 /** Decompress the SDI and store in the buffer passed. */
49 inline void decompress() {
50 int ret;
51 uLongf dest_len = m_uncomp_len;
52 ret = uncompress(m_uncomp_sdi, &dest_len, m_comp_sdi, m_comp_len);
53
54 if (ret != Z_OK) {
55 #ifdef UNIV_NO_ERR_MSGS
56 ib::error()
57 #else
58 ib::error(ER_IB_ERR_ZLIB_UNCOMPRESS_FAILED)
59 #endif
60 << "ZLIB uncompress() failed:"
61 << " compressed len: " << m_comp_len
62 << ", original_len: " << m_uncomp_len;
63
64 switch (ret) {
65 case Z_BUF_ERROR:
66 #ifdef UNIV_NO_ERR_MSGS
67 ib::fatal(UT_LOCATION_HERE)
68 #else
69 ib::fatal(UT_LOCATION_HERE, ER_IB_ERR_ZLIB_BUF_ERROR)
70 #endif
71
72 << "retval = Z_BUF_ERROR";
73 break;
74
75 case Z_MEM_ERROR:
76 #ifdef UNIV_NO_ERR_MSGS
77 ib::fatal(UT_LOCATION_HERE)
78 #else
79 ib::fatal(UT_LOCATION_HERE, ER_IB_ERR_ZLIB_MEM_ERROR)
80 #endif
81 << "retval = Z_MEM_ERROR";
82 break;
83
84 case Z_DATA_ERROR:
85 #ifdef UNIV_NO_ERR_MSGS
86 ib::fatal(UT_LOCATION_HERE)
87 #else
88 ib::fatal(UT_LOCATION_HERE, ER_IB_ERR_ZLIB_DATA_ERROR)
89 #endif
90 << "retval = Z_DATA_ERROR";
91 break;
92
93 default:
94 #ifdef UNIV_NO_ERR_MSGS
95 ib::fatal(UT_LOCATION_HERE)
96 #else
97 ib::fatal(UT_LOCATION_HERE, ER_IB_ERR_ZLIB_UNKNOWN_ERROR)
98 #endif
99 << "retval = UNKNOWN_ERROR";
100 break;
101 }
102 }
103 }
104
105 /** @return the uncompressed sdi */
106 byte *get_data() const { return (m_uncomp_sdi); }
107
108 private:
109 /** Buffer to hold uncompressed SDI. memory allocated by caller */
110 byte *m_uncomp_sdi;
111 /** Length of Outbuf Buffer */
112 uint32_t m_uncomp_len;
113 /** Input Compressed SDI */
114 byte *m_comp_sdi;
115 /** Length of Compressed SDI */
116 uint32_t m_comp_len;
117 };
118 #endif