Coverage Report

Created: 2026-11-22 17:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hdf5/src/H5Opline.c
Line
Count
Source
1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
 * Copyright by The HDF Group.                                               *
3
 * All rights reserved.                                                      *
4
 *                                                                           *
5
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
6
 * terms governing use, modification, and redistribution, is contained in    *
7
 * the LICENSE file, which can be found at the root of the source code       *
8
 * distribution tree, or in https://www.hdfgroup.org/licenses.               *
9
 * If you do not have access to either file, you may request a copy from     *
10
 * help@hdfgroup.org.                                                        *
11
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13
/*
14
 * Purpose:     Data filter pipeline message
15
 */
16
17
#include "H5Omodule.h" /* This source code file is part of the H5O module */
18
#define H5Z_FRIEND     /*suppress error about including H5Zpkg      */
19
20
#include "H5private.h"   /* Generic Functions            */
21
#include "H5Eprivate.h"  /* Error handling               */
22
#include "H5FLprivate.h" /* Free Lists                   */
23
#include "H5MMprivate.h" /* Memory management            */
24
#include "H5Opkg.h"      /* Object headers               */
25
#include "H5Zpkg.h"      /* Data filters                 */
26
27
/* PRIVATE PROTOTYPES */
28
static herr_t H5O__pline_encode(H5F_t *f, uint8_t *p, const void *mesg);
29
static void  *H5O__pline_decode(H5F_t *f, H5O_t *open_oh, unsigned mesg_flags, unsigned *ioflags,
30
                                size_t p_size, const uint8_t *p);
31
static void  *H5O__pline_copy(const void *_mesg, void *_dest);
32
static size_t H5O__pline_size(const H5F_t *f, const void *_mesg);
33
static herr_t H5O__pline_reset(void *_mesg);
34
static herr_t H5O__pline_free(void *_mesg);
35
static herr_t H5O__pline_pre_copy_file(H5F_t *file_src, const void *mesg_src, bool *deleted,
36
                                       const H5O_copy_t *cpy_info, void *_udata);
37
static herr_t H5O__pline_debug(H5F_t *f, const void *_mesg, FILE *stream, int indent, int fwidth);
38
39
/* Set up & include shared message "interface" info */
40
0
#define H5O_SHARED_TYPE        H5O_MSG_PLINE
41
#define H5O_SHARED_DECODE      H5O__pline_shared_decode
42
1
#define H5O_SHARED_DECODE_REAL H5O__pline_decode
43
#define H5O_SHARED_ENCODE      H5O__pline_shared_encode
44
0
#define H5O_SHARED_ENCODE_REAL H5O__pline_encode
45
#define H5O_SHARED_SIZE        H5O__pline_shared_size
46
0
#define H5O_SHARED_SIZE_REAL   H5O__pline_size
47
#define H5O_SHARED_DELETE      H5O__pline_shared_delete
48
#undef H5O_SHARED_DELETE_REAL
49
#define H5O_SHARED_LINK H5O__pline_shared_link
50
#undef H5O_SHARED_LINK_REAL
51
#define H5O_SHARED_COPY_FILE H5O__pline_shared_copy_file
52
#undef H5O_SHARED_COPY_FILE_REAL
53
#define H5O_SHARED_POST_COPY_FILE H5O__pline_shared_post_copy_file
54
#undef H5O_SHARED_POST_COPY_FILE_REAL
55
#undef H5O_SHARED_POST_COPY_FILE_UPD
56
#define H5O_SHARED_DEBUG      H5O__pline_shared_debug
57
0
#define H5O_SHARED_DEBUG_REAL H5O__pline_debug
58
#include "H5Oshared.h" /* Shared Object Header Message Callbacks */
59
60
/* This message derives from H5O message class */
61
const H5O_msg_class_t H5O_MSG_PLINE[1] = {{
62
    H5O_PLINE_ID,                              /* message id number            */
63
    "filter pipeline",                         /* message name for debugging   */
64
    sizeof(H5O_pline_t),                       /* native message size          */
65
    H5O_SHARE_IS_SHARABLE | H5O_SHARE_IN_OHDR, /* messages are shareable?       */
66
    H5O__pline_shared_decode,                  /* decode message               */
67
    H5O__pline_shared_encode,                  /* encode message               */
68
    H5O__pline_copy,                           /* copy the native value        */
69
    H5O__pline_shared_size,                    /* size of raw message          */
70
    H5O__pline_reset,                          /* reset method                 */
71
    H5O__pline_free,                           /* free method                  */
72
    H5O__pline_shared_delete,                  /* file delete method           */
73
    H5O__pline_shared_link,                    /* link method                  */
74
    NULL,                                      /* set share method             */
75
    NULL,                                      /*can share method              */
76
    H5O__pline_pre_copy_file,                  /* pre copy native value to file */
77
    H5O__pline_shared_copy_file,               /* copy native value to file    */
78
    H5O__pline_shared_post_copy_file,          /* post copy native value to file */
79
    NULL,                                      /* get creation index           */
80
    NULL,                                      /* set creation index           */
81
    H5O__pline_shared_debug                    /* debug the message            */
82
}};
83
84
/* Format version bounds for filter pipeline */
85
const unsigned H5O_pline_ver_bounds[] = {
86
    H5O_PLINE_VERSION_1,     /* H5F_LIBVER_EARLIEST */
87
    H5O_PLINE_VERSION_2,     /* H5F_LIBVER_V18 */
88
    H5O_PLINE_VERSION_2,     /* H5F_LIBVER_V110 */
89
    H5O_PLINE_VERSION_2,     /* H5F_LIBVER_V112 */
90
    H5O_PLINE_VERSION_2,     /* H5F_LIBVER_V114 */
91
    H5O_PLINE_VERSION_2,     /* H5F_LIBVER_V200 */
92
    H5O_PLINE_VERSION_LATEST /* H5F_LIBVER_LATEST */
93
};
94
95
/* Declare a free list to manage the H5O_pline_t struct */
96
H5FL_DEFINE(H5O_pline_t);
97
98
/*-------------------------------------------------------------------------
99
 * Function:    H5O__pline_decode
100
 *
101
 * Purpose:     Decodes a filter pipeline message.
102
 *
103
 * Return:      Success:    Pointer to a new pipeline message
104
 *              Failure:    NULL
105
 *-------------------------------------------------------------------------
106
 */
107
108
static void *
109
H5O__pline_decode(H5F_t H5_ATTR_UNUSED *f, H5O_t H5_ATTR_UNUSED *open_oh, unsigned H5_ATTR_UNUSED mesg_flags,
110
                  unsigned H5_ATTR_UNUSED *ioflags, size_t p_size, const uint8_t *p)
111
1
{
112
1
    H5O_pline_t       *pline = NULL;               /* Pipeline message */
113
1
    H5Z_filter_info_t *filter;                     /* Filter to decode */
114
1
    size_t             name_length;                /* Length of filter name */
115
1
    size_t             i;                          /* Local index variable */
116
1
    const uint8_t     *p_end     = p + p_size - 1; /* End of the p buffer */
117
1
    void              *ret_value = NULL;
118
119
1
    FUNC_ENTER_PACKAGE
120
121
1
    assert(f);
122
1
    assert(p);
123
124
    /* Allocate space for I/O pipeline message */
125
1
    if (NULL == (pline = H5FL_CALLOC(H5O_pline_t)))
126
0
        HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
127
128
    /* Version */
129
1
    if (H5_IS_BUFFER_OVERFLOW(p, 1, p_end))
130
0
        HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding");
131
1
    pline->version = *p++;
132
1
    if (pline->version < H5O_PLINE_VERSION_1 || pline->version > H5O_PLINE_VERSION_LATEST)
133
0
        HGOTO_ERROR(H5E_PLINE, H5E_CANTLOAD, NULL, "bad version number for filter pipeline message");
134
135
    /* Number of filters */
136
1
    if (H5_IS_BUFFER_OVERFLOW(p, 1, p_end))
137
0
        HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding");
138
1
    pline->nused = *p++;
139
1
    if (pline->nused > H5Z_MAX_NFILTERS) {
140
141
        /* Reset the number of filters used to avoid array traversal in error
142
         * handling code.
143
         */
144
0
        pline->nused = 0;
145
146
0
        HGOTO_ERROR(H5E_PLINE, H5E_CANTLOAD, NULL, "filter pipeline message has too many filters");
147
0
    }
148
149
    /* Reserved */
150
1
    if (pline->version == H5O_PLINE_VERSION_1) {
151
0
        if (H5_IS_BUFFER_OVERFLOW(p, 6, p_end))
152
0
            HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding");
153
0
        p += 6;
154
0
    }
155
156
    /* Allocate array for filters */
157
1
    pline->nalloc = pline->nused;
158
1
    if (NULL == (pline->filter = (H5Z_filter_info_t *)H5MM_calloc(pline->nalloc * sizeof(pline->filter[0]))))
159
0
        HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
160
161
    /* Decode filters */
162
2
    for (i = 0, filter = &pline->filter[0]; i < pline->nused; i++, filter++) {
163
        /* Filter ID */
164
1
        if (H5_IS_BUFFER_OVERFLOW(p, 2, p_end))
165
0
            HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding");
166
1
        UINT16DECODE(p, filter->id);
167
168
        /* Length of filter name */
169
1
        if (pline->version > H5O_PLINE_VERSION_1 && filter->id < H5Z_FILTER_RESERVED)
170
1
            name_length = 0;
171
0
        else {
172
0
            if (H5_IS_BUFFER_OVERFLOW(p, 2, p_end))
173
0
                HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding");
174
0
            UINT16DECODE(p, name_length);
175
0
            if (pline->version == H5O_PLINE_VERSION_1 && name_length % 8)
176
0
                HGOTO_ERROR(H5E_PLINE, H5E_CANTLOAD, NULL, "filter name length is not a multiple of eight");
177
0
        }
178
179
        /* Filter flags */
180
1
        if (H5_IS_BUFFER_OVERFLOW(p, 2, p_end))
181
0
            HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding");
182
1
        UINT16DECODE(p, filter->flags);
183
184
        /* Number of filter parameters ("client data elements") */
185
1
        if (H5_IS_BUFFER_OVERFLOW(p, 2, p_end))
186
0
            HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding");
187
1
        UINT16DECODE(p, filter->cd_nelmts);
188
189
        /* Filter name, if there is one */
190
1
        if (name_length) {
191
0
            size_t actual_name_length;            /* Actual length of name */
192
0
            size_t max = (size_t)(p_end - p + 1); /* Max possible name length */
193
194
            /* Determine actual name length (without padding, but with null terminator) */
195
0
            actual_name_length = strnlen((const char *)p, max);
196
0
            if (actual_name_length == max)
197
0
                HGOTO_ERROR(H5E_OHDR, H5E_NOSPACE, NULL, "filter name not null terminated");
198
0
            actual_name_length += 1; /* include \0 byte */
199
200
            /* Allocate space for the filter name, or use the internal buffer */
201
0
            if (actual_name_length > H5Z_COMMON_NAME_LEN) {
202
0
                filter->name = (char *)H5MM_malloc(actual_name_length);
203
0
                if (NULL == filter->name)
204
0
                    HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for filter name");
205
0
            }
206
0
            else
207
0
                filter->name = filter->_name;
208
209
0
            strncpy(filter->name, (const char *)p, actual_name_length);
210
211
0
            if (H5_IS_BUFFER_OVERFLOW(p, name_length, p_end))
212
0
                HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding");
213
0
            p += name_length;
214
0
        }
215
216
        /* Filter parameters */
217
1
        if (filter->cd_nelmts) {
218
219
            /* Allocate space for the client data elements, or use the internal buffer */
220
0
            if (filter->cd_nelmts > H5Z_COMMON_CD_VALUES) {
221
0
                filter->cd_values = (unsigned *)H5MM_malloc(filter->cd_nelmts * sizeof(unsigned));
222
0
                if (NULL == filter->cd_values)
223
0
                    HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for client data");
224
0
            }
225
0
            else
226
0
                filter->cd_values = filter->_cd_values;
227
228
            /* Read the client data values and the padding */
229
0
            for (size_t j = 0; j < filter->cd_nelmts; j++) {
230
0
                if (H5_IS_BUFFER_OVERFLOW(p, 4, p_end))
231
0
                    HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding");
232
0
                UINT32DECODE(p, filter->cd_values[j]);
233
0
            }
234
235
0
            if (pline->version == H5O_PLINE_VERSION_1)
236
0
                if (filter->cd_nelmts % 2) {
237
0
                    if (H5_IS_BUFFER_OVERFLOW(p, 4, p_end))
238
0
                        HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL,
239
0
                                    "ran off end of input buffer while decoding");
240
0
                    p += 4; /* padding */
241
0
                }
242
0
        }
243
1
    }
244
245
    /* Set return value */
246
1
    ret_value = pline;
247
248
1
done:
249
1
    if (!ret_value && pline) {
250
0
        H5O__pline_reset(pline);
251
0
        H5O__pline_free(pline);
252
0
    }
253
254
1
    FUNC_LEAVE_NOAPI(ret_value)
255
1
} /* end H5O__pline_decode() */
256
257
/*-------------------------------------------------------------------------
258
 * Function:    H5O__pline_encode
259
 *
260
 * Purpose:    Encodes message MESG into buffer P.
261
 *
262
 * Return:    Non-negative on success/Negative on failure
263
 *
264
 *-------------------------------------------------------------------------
265
 */
266
static herr_t
267
H5O__pline_encode(H5F_t H5_ATTR_UNUSED *f, uint8_t *p /*out*/, const void *mesg)
268
0
{
269
0
    const H5O_pline_t       *pline = (const H5O_pline_t *)mesg; /* Pipeline message to encode */
270
0
    const H5Z_filter_info_t *filter;                            /* Filter to encode */
271
0
    size_t                   i, j;                              /* Local index variables */
272
273
0
    FUNC_ENTER_PACKAGE_NOERR
274
275
    /* Check args */
276
0
    assert(p);
277
0
    assert(mesg);
278
279
    /* Message header */
280
0
    *p++ = (uint8_t)pline->version;
281
0
    *p++ = (uint8_t)(pline->nused);
282
0
    if (pline->version == H5O_PLINE_VERSION_1) {
283
0
        *p++ = 0; /*reserved 1*/
284
0
        *p++ = 0; /*reserved 2*/
285
0
        *p++ = 0; /*reserved 3*/
286
0
        *p++ = 0; /*reserved 4*/
287
0
        *p++ = 0; /*reserved 5*/
288
0
        *p++ = 0; /*reserved 6*/
289
0
    }             /* end if */
290
291
    /* Encode filters */
292
0
    for (i = 0, filter = &pline->filter[0]; i < pline->nused; i++, filter++) {
293
0
        const char *name;        /* Filter name */
294
0
        size_t      name_length; /* Length of filter name */
295
296
        /* Filter ID */
297
0
        UINT16ENCODE(p, filter->id);
298
299
        /* Skip writing the name length & name if the filter is an internal filter */
300
0
        if (pline->version > H5O_PLINE_VERSION_1 && filter->id < H5Z_FILTER_RESERVED) {
301
0
            name_length = 0;
302
0
            name        = NULL;
303
0
        } /* end if */
304
0
        else {
305
            /*
306
             * Get the filter name.  If the pipeline message has a name in it then
307
             * use that one.  Otherwise try to look up the filter and get the name
308
             * as it was registered.
309
             */
310
0
            if (NULL == (name = filter->name)) {
311
0
                H5Z_class2_t *cls; /* Filter class */
312
313
0
                H5Z_find(true, filter->id, &cls);
314
0
                if (cls)
315
0
                    name = cls->name;
316
0
            }
317
0
            name_length = name ? strlen(name) + 1 : 0;
318
319
            /* Filter name length */
320
0
            UINT16ENCODE(p, pline->version == H5O_PLINE_VERSION_1 ? H5O_ALIGN_OLD(name_length) : name_length);
321
0
        } /* end else */
322
323
        /* Filter flags */
324
0
        UINT16ENCODE(p, filter->flags);
325
326
        /* # of filter parameters */
327
0
        UINT16ENCODE(p, filter->cd_nelmts);
328
329
        /* Encode name, if there is one to encode */
330
0
        if (name_length > 0) {
331
            /* Store name, with null terminator */
332
0
            H5MM_memcpy(p, name, name_length);
333
0
            p += name_length;
334
335
            /* Pad out name to alignment, in older versions */
336
0
            if (pline->version == H5O_PLINE_VERSION_1)
337
0
                while (name_length++ % 8)
338
0
                    *p++ = 0;
339
0
        } /* end if */
340
341
        /* Filter parameters */
342
0
        for (j = 0; j < filter->cd_nelmts; j++)
343
0
            UINT32ENCODE(p, filter->cd_values[j]);
344
345
        /* Align the parameters for older versions of the format */
346
0
        if (pline->version == H5O_PLINE_VERSION_1)
347
0
            if (filter->cd_nelmts % 2)
348
0
                UINT32ENCODE(p, 0);
349
0
    } /* end for */
350
351
0
    FUNC_LEAVE_NOAPI(SUCCEED)
352
0
} /* end H5O__pline_encode() */
353
354
/*-------------------------------------------------------------------------
355
 * Function:    H5O__pline_copy
356
 *
357
 * Purpose:    Copies a filter pipeline message from SRC to DST allocating
358
 *        DST if necessary.  If DST is already allocated then we assume
359
 *        that it isn't initialized.
360
 *
361
 * Return:    Success:    Ptr to DST or allocated result.
362
 *
363
 *        Failure:    NULL
364
 *
365
 *-------------------------------------------------------------------------
366
 */
367
static void *
368
H5O__pline_copy(const void *_src, void *_dst /*out*/)
369
20.1k
{
370
20.1k
    const H5O_pline_t *src = (const H5O_pline_t *)_src; /* Source pipeline message */
371
20.1k
    H5O_pline_t       *dst = (H5O_pline_t *)_dst;       /* Destination pipeline message */
372
20.1k
    size_t             i;                               /* Local index variable */
373
20.1k
    H5O_pline_t       *ret_value = NULL;                /* Return value */
374
375
20.1k
    FUNC_ENTER_PACKAGE
376
377
    /* Allocate pipeline message, if not provided */
378
20.1k
    if (!dst && NULL == (dst = H5FL_MALLOC(H5O_pline_t)))
379
0
        HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
380
381
    /* Shallow copy basic fields */
382
20.1k
    *dst = *src;
383
384
    /* Copy over filters, if any */
385
20.1k
    dst->nalloc = dst->nused;
386
20.1k
    if (dst->nalloc) {
387
        /* Allocate array to hold filters */
388
18
        if (NULL == (dst->filter = (H5Z_filter_info_t *)H5MM_calloc(dst->nalloc * sizeof(dst->filter[0]))))
389
0
            HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
390
391
        /* Deep-copy filters */
392
36
        for (i = 0; i < src->nused; i++) {
393
            /* Basic filter information */
394
18
            dst->filter[i] = src->filter[i];
395
396
            /* Filter name */
397
18
            if (src->filter[i].name) {
398
0
                size_t namelen; /* Length of source filter name, including null terminator  */
399
400
0
                namelen = strlen(src->filter[i].name) + 1;
401
402
                /* Allocate space for the filter name, or use the internal buffer */
403
0
                if (namelen > H5Z_COMMON_NAME_LEN) {
404
0
                    dst->filter[i].name = (char *)H5MM_strdup(src->filter[i].name);
405
0
                    if (NULL == dst->filter[i].name)
406
0
                        HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL,
407
0
                                    "memory allocation failed for filter name");
408
0
                } /* end if */
409
0
                else
410
0
                    dst->filter[i].name = dst->filter[i]._name;
411
0
            } /* end if */
412
413
            /* Filter parameters */
414
18
            if (src->filter[i].cd_nelmts > 0) {
415
                /* Allocate space for the client data elements, or use the internal buffer */
416
0
                if (src->filter[i].cd_nelmts > H5Z_COMMON_CD_VALUES) {
417
0
                    if (NULL == (dst->filter[i].cd_values =
418
0
                                     (unsigned *)H5MM_malloc(src->filter[i].cd_nelmts * sizeof(unsigned))))
419
0
                        HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
420
421
0
                    H5MM_memcpy(dst->filter[i].cd_values, src->filter[i].cd_values,
422
0
                                src->filter[i].cd_nelmts * sizeof(unsigned));
423
0
                } /* end if */
424
0
                else
425
0
                    dst->filter[i].cd_values = dst->filter[i]._cd_values;
426
0
            } /* end if */
427
18
        }     /* end for */
428
18
    }         /* end if */
429
20.1k
    else
430
20.1k
        dst->filter = NULL;
431
432
    /* Set return value */
433
20.1k
    ret_value = dst;
434
435
20.1k
done:
436
20.1k
    if (!ret_value && dst) {
437
0
        H5O__pline_reset(dst);
438
0
        if (!_dst)
439
0
            H5O__pline_free(dst);
440
0
    } /* end if */
441
442
20.1k
    FUNC_LEAVE_NOAPI(ret_value)
443
20.1k
} /* end H5O__pline_copy() */
444
445
/*-------------------------------------------------------------------------
446
 * Function:    H5O__pline_size
447
 *
448
 * Purpose:    Determines the size of a raw filter pipeline message.
449
 *
450
 * Return:    Success:    Size of message.
451
 *
452
 *        Failure:    zero
453
 *
454
 *-------------------------------------------------------------------------
455
 */
456
static size_t
457
H5O__pline_size(const H5F_t H5_ATTR_UNUSED *f, const void *mesg)
458
0
{
459
0
    const H5O_pline_t *pline = (const H5O_pline_t *)mesg; /* Pipeline message */
460
0
    size_t             i;                                 /* Local index variable */
461
0
    size_t             ret_value = 0;                     /* Return value */
462
463
0
    FUNC_ENTER_PACKAGE_NOERR
464
465
    /* Message header */
466
0
    ret_value = (size_t)(1 +                                               /*version            */
467
0
                         1 +                                               /*number of filters        */
468
0
                         (pline->version == H5O_PLINE_VERSION_1 ? 6 : 0)); /*reserved            */
469
470
    /* Calculate size of each filter in pipeline */
471
0
    for (i = 0; i < pline->nused; i++) {
472
0
        size_t      name_len; /* Length of filter name */
473
0
        const char *name;     /* Filter name */
474
475
        /* Don't write the name length & name if the filter is an internal filter */
476
0
        if (pline->version > H5O_PLINE_VERSION_1 && pline->filter[i].id < H5Z_FILTER_RESERVED)
477
0
            name_len = 0;
478
0
        else {
479
            /* Get the name of the filter, same as done with H5O__pline_encode() */
480
0
            if (NULL == (name = pline->filter[i].name)) {
481
0
                H5Z_class2_t *cls; /* Filter class */
482
483
0
                H5Z_find(true, pline->filter[i].id, &cls);
484
0
                if (cls)
485
0
                    name = cls->name;
486
0
            }
487
0
            name_len = name ? strlen(name) + 1 : 0;
488
0
        } /* end else */
489
490
0
        ret_value +=
491
0
            2 + /*filter identification number    */
492
0
            (size_t)((pline->version == H5O_PLINE_VERSION_1 || pline->filter[i].id >= H5Z_FILTER_RESERVED)
493
0
                         ? 2
494
0
                         : 0) + /*name length            */
495
0
            2 +                 /*flags                */
496
0
            2 +                 /*number of client data values    */
497
0
            (pline->version == H5O_PLINE_VERSION_1 ? (size_t)H5O_ALIGN_OLD(name_len)
498
0
                                                   : name_len); /*length of the filter name    */
499
500
0
        ret_value += pline->filter[i].cd_nelmts * 4;
501
0
        if (pline->version == H5O_PLINE_VERSION_1)
502
0
            if (pline->filter[i].cd_nelmts % 2)
503
0
                ret_value += 4;
504
0
    } /* end for */
505
506
0
    FUNC_LEAVE_NOAPI(ret_value)
507
0
} /* end H5O__pline_size() */
508
509
/*-------------------------------------------------------------------------
510
 * Function:    H5O__pline_reset
511
 *
512
 * Purpose:    Resets a filter pipeline message by clearing all filters.
513
 *        The MESG buffer is not freed.
514
 *
515
 * Return:    Non-negative on success/Negative on failure
516
 *
517
 *-------------------------------------------------------------------------
518
 */
519
static herr_t
520
H5O__pline_reset(void *mesg)
521
24.8k
{
522
24.8k
    H5O_pline_t *pline = (H5O_pline_t *)mesg; /* Pipeline message */
523
24.8k
    size_t       i;                           /* Local index variable */
524
525
24.8k
    FUNC_ENTER_PACKAGE_NOERR
526
527
    /* NOTE: This function can be called during error processing from
528
     *       other API calls so DO NOT ASSUME THAT ANY VALUES ARE SANE.
529
     */
530
531
24.8k
    assert(pline);
532
533
    /* Free the filter information and array */
534
24.8k
    if (pline->filter) {
535
        /* Free information for each filter */
536
38
        for (i = 0; i < pline->nused; i++) {
537
19
            if (pline->filter[i].name && pline->filter[i].name != pline->filter[i]._name)
538
19
                assert((strlen(pline->filter[i].name) + 1) > H5Z_COMMON_NAME_LEN);
539
19
            if (pline->filter[i].name != pline->filter[i]._name)
540
19
                pline->filter[i].name = (char *)H5MM_xfree(pline->filter[i].name);
541
19
            if (pline->filter[i].cd_values && pline->filter[i].cd_values != pline->filter[i]._cd_values)
542
19
                assert(pline->filter[i].cd_nelmts > H5Z_COMMON_CD_VALUES);
543
19
            if (pline->filter[i].cd_values != pline->filter[i]._cd_values)
544
19
                pline->filter[i].cd_values = (unsigned *)H5MM_xfree(pline->filter[i].cd_values);
545
19
        } /* end for */
546
547
        /* Free filter array */
548
19
        pline->filter = (H5Z_filter_info_t *)H5MM_xfree(pline->filter);
549
19
    }
550
551
    /* Reset # of filters */
552
24.8k
    pline->nused = pline->nalloc = 0;
553
554
    /* Reset version # of pipeline message */
555
24.8k
    pline->version = H5O_PLINE_VERSION_1;
556
557
24.8k
    FUNC_LEAVE_NOAPI(SUCCEED)
558
24.8k
} /* end H5O__pline_reset() */
559
560
/*-------------------------------------------------------------------------
561
 * Function:    H5O__pline_free
562
 *
563
 * Purpose:    Frees the message
564
 *
565
 * Return:    Non-negative on success/Negative on failure
566
 *
567
 *-------------------------------------------------------------------------
568
 */
569
static herr_t
570
H5O__pline_free(void *mesg)
571
1
{
572
1
    FUNC_ENTER_PACKAGE_NOERR
573
574
1
    assert(mesg);
575
576
1
    mesg = H5FL_FREE(H5O_pline_t, mesg);
577
578
1
    FUNC_LEAVE_NOAPI(SUCCEED)
579
1
} /* end H5O__pline_free() */
580
581
/*-------------------------------------------------------------------------
582
 * Function:    H5O__pline_pre_copy_file
583
 *
584
 * Purpose:     Perform any necessary actions before copying message between
585
 *              files
586
 *
587
 * Return:      Success:        Non-negative
588
 *
589
 *              Failure:        Negative
590
 *
591
 *-------------------------------------------------------------------------
592
 */
593
static herr_t
594
H5O__pline_pre_copy_file(H5F_t H5_ATTR_UNUSED *file_src, const void *mesg_src, bool H5_ATTR_UNUSED *deleted,
595
                         const H5O_copy_t *cpy_info, void *_udata)
596
0
{
597
0
    const H5O_pline_t         *pline_src = (const H5O_pline_t *)mesg_src;       /* Source pline */
598
0
    H5O_copy_file_ud_common_t *udata     = (H5O_copy_file_ud_common_t *)_udata; /* Object copying user data */
599
0
    herr_t                     ret_value = SUCCEED;                             /* Return value */
600
601
0
    FUNC_ENTER_PACKAGE
602
603
    /* check args */
604
0
    assert(pline_src);
605
0
    assert(cpy_info);
606
0
    assert(cpy_info->file_dst);
607
608
    /* Check to ensure that the version of the message to be copied does not exceed
609
       the message version allowed by the destination file's high bound */
610
0
    if (pline_src->version > H5O_pline_ver_bounds[H5F_HIGH_BOUND(cpy_info->file_dst)])
611
0
        HGOTO_ERROR(H5E_OHDR, H5E_BADRANGE, FAIL, "pline message version out of bounds");
612
613
    /* If the user data is non-NULL, assume we are copying a dataset or group
614
     * and make a copy of the filter pipeline for later in
615
     * the object copying process.
616
     */
617
0
    if (udata)
618
0
        if (NULL == (udata->src_pline = (H5O_pline_t *)H5O__pline_copy(pline_src, NULL)))
619
0
            HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, FAIL, "unable to copy");
620
621
0
done:
622
0
    FUNC_LEAVE_NOAPI(ret_value)
623
0
} /* end H5O__pline_pre_copy_file() */
624
625
/*-------------------------------------------------------------------------
626
 * Function:    H5O__pline_debug
627
 *
628
 * Purpose:    Prints debugging information for filter pipeline message MESG
629
 *        on output stream STREAM.  Each line is indented INDENT
630
 *        characters and the field name takes up FWIDTH characters.
631
 *
632
 * Return:    Non-negative on success/Negative on failure
633
 *
634
 *-------------------------------------------------------------------------
635
 */
636
static herr_t
637
H5O__pline_debug(H5F_t H5_ATTR_UNUSED *f, const void *mesg, FILE *stream, int indent, int fwidth)
638
0
{
639
0
    const H5O_pline_t *pline = (const H5O_pline_t *)mesg;
640
641
0
    FUNC_ENTER_PACKAGE_NOERR
642
643
    /* check args */
644
0
    assert(f);
645
0
    assert(pline);
646
0
    assert(stream);
647
0
    assert(indent >= 0);
648
0
    assert(fwidth >= 0);
649
650
0
    fprintf(stream, "%*s%-*s %zu/%zu\n", indent, "", fwidth, "Number of filters:", pline->nused,
651
0
            pline->nalloc);
652
653
    /* Loop over all the filters */
654
0
    for (size_t i = 0; i < pline->nused; i++) {
655
        /* 19 characters for text + 20 characters for largest 64-bit size_t +
656
         * terminal NUL = 40 characters.
657
         */
658
0
        char name[64];
659
660
0
        memset(name, 0, 64);
661
0
        snprintf(name, sizeof(name), "Filter at position %zu", i);
662
663
0
        fprintf(stream, "%*s%-*s\n", indent, "", fwidth, name);
664
0
        fprintf(stream, "%*s%-*s 0x%04x\n", indent + 3, "", MAX(0, fwidth - 3),
665
0
                "Filter identification:", (unsigned)(pline->filter[i].id));
666
0
        if (pline->filter[i].name)
667
0
            fprintf(stream, "%*s%-*s \"%s\"\n", indent + 3, "", MAX(0, fwidth - 3),
668
0
                    "Filter name:", pline->filter[i].name);
669
0
        else
670
0
            fprintf(stream, "%*s%-*s NONE\n", indent + 3, "", MAX(0, fwidth - 3), "Filter name:");
671
0
        fprintf(stream, "%*s%-*s 0x%04x\n", indent + 3, "", MAX(0, fwidth - 3),
672
0
                "Flags:", pline->filter[i].flags);
673
0
        fprintf(stream, "%*s%-*s %zu\n", indent + 3, "", MAX(0, fwidth - 3),
674
0
                "Num CD values:", pline->filter[i].cd_nelmts);
675
676
        /* Filter parameters */
677
0
        for (size_t j = 0; j < pline->filter[i].cd_nelmts; j++) {
678
0
            char field_name[32];
679
680
0
            snprintf(field_name, sizeof(field_name), "CD value %lu", (unsigned long)j);
681
0
            fprintf(stream, "%*s%-*s %u\n", indent + 6, "", MAX(0, fwidth - 6), field_name,
682
0
                    pline->filter[i].cd_values[j]);
683
0
        }
684
0
    }
685
686
0
    FUNC_LEAVE_NOAPI(SUCCEED)
687
0
} /* end H5O__pline_debug() */
688
689
/*-------------------------------------------------------------------------
690
 * Function:    H5O_pline_set_version
691
 *
692
 * Purpose:     Set the version to encode an I/O filter pipeline with.
693
 *
694
 * Return:      Non-negative on success/Negative on failure
695
 *
696
 *-------------------------------------------------------------------------
697
 */
698
herr_t
699
H5O_pline_set_version(H5F_t *f, H5O_pline_t *pline)
700
0
{
701
0
    unsigned version;             /* Message version */
702
0
    herr_t   ret_value = SUCCEED; /* Return value */
703
704
0
    FUNC_ENTER_NOAPI(FAIL)
705
706
    /* Sanity check */
707
0
    assert(f);
708
0
    assert(pline);
709
710
    /* Upgrade to the version indicated by the file's low bound if higher */
711
0
    version = MAX(pline->version, H5O_pline_ver_bounds[H5F_LOW_BOUND(f)]);
712
713
    /* Version bounds check */
714
0
    if (version > H5O_pline_ver_bounds[H5F_HIGH_BOUND(f)])
715
0
        HGOTO_ERROR(H5E_PLINE, H5E_BADRANGE, FAIL, "Filter pipeline version out of bounds");
716
717
    /* Set the message version */
718
0
    pline->version = version;
719
720
0
done:
721
0
    FUNC_LEAVE_NOAPI(ret_value)
722
0
} /* end H5O_pline_set_version() */