Source
96
96
97
97
98
98
/* Declare extern the free list to manage the H5G_node_t struct */
99
99
H5FL_EXTERN(H5G_node_t);
100
100
101
101
/* Declare extern the free list to manage sequences of H5G_entry_t's */
102
102
H5FL_SEQ_EXTERN(H5G_entry_t);
103
103
104
104
•
105
105
/*-------------------------------------------------------------------------
106
-
* Function: H5G_node_load
106
+
* Function: H5G_node_load
107
107
*
108
-
* Purpose: Loads a symbol table node from the file.
108
+
* Purpose: Loads a symbol table node from the file.
109
109
*
110
-
* Return: Success: Ptr to the new table.
110
+
* Return: Success: Ptr to the new table.
111
+
* Failure: NULL
111
112
*
112
-
* Failure: NULL
113
-
*
114
-
* Programmer: Robb Matzke
115
-
* matzke@llnl.gov
116
-
* Jun 23 1997
113
+
* Programmer: Robb Matzke
114
+
* matzke@llnl.gov
115
+
* Jun 23 1997
117
116
*
118
117
*-------------------------------------------------------------------------
119
118
*/
120
119
static H5G_node_t *
121
120
H5G_node_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, void *udata)
122
121
{
123
-
H5G_node_t *sym = NULL;
124
-
H5WB_t *wb = NULL; /* Wrapped buffer for node data */
125
-
uint8_t node_buf[H5G_NODE_BUF_SIZE]; /* Buffer for node */
126
-
uint8_t *node; /* Pointer to node buffer */
122
+
H5G_node_t *sym = NULL;
123
+
H5WB_t *wb = NULL; /* Wrapped buffer for node data */
124
+
uint8_t node_buf[H5G_NODE_BUF_SIZE]; /* Buffer for node */
125
+
uint8_t *node; /* Pointer to node buffer */
127
126
const uint8_t *p;
128
-
H5G_node_t *ret_value; /*for error handling */
127
+
const uint8_t *p_end;
128
+
H5G_node_t *ret_value; /* Return value */
129
129
130
130
FUNC_ENTER_NOAPI_NOINIT
131
131
132
-
/*
133
-
* Check arguments.
134
-
*/
132
+
/* Sanity checks */
135
133
HDassert(f);
136
134
HDassert(H5F_addr_defined(addr));
137
135
HDassert(udata);
138
136
139
-
/*
140
-
* Initialize variables.
141
-
*/
142
-
143
137
/* Allocate symbol table data structures */
144
138
if(NULL == (sym = H5FL_CALLOC(H5G_node_t)))
145
-
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
139
+
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
146
140
sym->node_size = H5G_NODE_SIZE(f);
147
141
if(NULL == (sym->entry = H5FL_SEQ_CALLOC(H5G_entry_t, (size_t)(2 * H5F_SYM_LEAF_K(f)))))
148
-
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
142
+
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
149
143
150
144
/* Wrap the local buffer for serialized node info */
151
145
if(NULL == (wb = H5WB_wrap(node_buf, sizeof(node_buf))))
152
146
HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, NULL, "can't wrap buffer")
153
147
154
148
/* Get a pointer to a buffer that's large enough for node */
155
149
if(NULL == (node = (uint8_t *)H5WB_actual(wb, sym->node_size)))
156
150
HGOTO_ERROR(H5E_SYM, H5E_NOSPACE, NULL, "can't get actual buffer")
157
151
158
152
/* Read the serialized symbol table node. */
159
153
if(H5F_block_read(f, H5FD_MEM_BTREE, addr, sym->node_size, dxpl_id, node) < 0)
160
-
HGOTO_ERROR(H5E_SYM, H5E_READERROR, NULL, "unable to read symbol table node")
154
+
HGOTO_ERROR(H5E_SYM, H5E_READERROR, NULL, "unable to read symbol table node")
161
155
162
156
/* Get temporary pointer to serialized node */
163
157
p = node;
164
158
159
+
/* Get a pointer to the end of the node. This ensures we don't run off
160
+
* the end of the buffer if the file is corrupt.
161
+
*/
162
+
p_end = p + sym->node_size - 1;
163
+
165
164
/* magic */
166
165
if(HDmemcmp(p, H5G_NODE_MAGIC, (size_t)H5_SIZEOF_MAGIC))
167
-
HGOTO_ERROR(H5E_SYM, H5E_CANTLOAD, NULL, "bad symbol table node signature")
166
+
HGOTO_ERROR(H5E_SYM, H5E_CANTLOAD, NULL, "bad symbol table node signature")
168
167
p += 4;
169
168
170
169
/* version */
171
170
if(H5G_NODE_VERS != *p++)
172
-
HGOTO_ERROR(H5E_SYM, H5E_CANTLOAD, NULL, "bad symbol table node version")
171
+
HGOTO_ERROR(H5E_SYM, H5E_CANTLOAD, NULL, "bad symbol table node version")
173
172
174
173
/* reserved */
175
174
p++;
176
175
177
176
/* number of symbols */
178
177
UINT16DECODE(p, sym->nsyms);
179
178
180
179
/* entries */
181
-
if(H5G__ent_decode_vec(f, &p, sym->entry, sym->nsyms) < 0)
182
-
HGOTO_ERROR(H5E_SYM, H5E_CANTLOAD, NULL, "unable to decode symbol table entries")
180
+
if(H5G__ent_decode_vec(f, &p, p_end, sym->entry, sym->nsyms) < 0)
181
+
HGOTO_ERROR(H5E_SYM, H5E_CANTLOAD, NULL, "unable to decode symbol table entries")
183
182
184
183
/* Set return value */
185
184
ret_value = sym;
186
185
187
186
done:
188
187
/* Release resources */
189
188
if(wb && H5WB_unwrap(wb) < 0)
190
189
HDONE_ERROR(H5E_SYM, H5E_CLOSEERROR, NULL, "can't close wrapped buffer")
191
190
if(!ret_value)
192
191
if(sym && H5G__node_free(sym) < 0)