Skip to content

Commit f2d1484

Browse files
committed
Add protections on frame/chunk versions and forward compatibility improvements
1 parent 8eeda93 commit f2d1484

File tree

5 files changed

+419
-6
lines changed

5 files changed

+419
-6
lines changed

RELEASING.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,32 @@ Then, test the file created with the new version with::
5757
Repeat this for every codec shipped with Blosc (blosclz, lz4, lz4hc, zlib and
5858
zstd).
5959

60+
For VL-block cframe compatibility checks, use ``compat/filegen-vl``.
61+
This utility can generate two kinds of persistent cframes:
62+
63+
* a cframe with VL-block chunks and fixed chunk sizes
64+
* a cframe with VL-block chunks and variable chunk sizes
65+
66+
Generate them with the current version::
67+
68+
$ cd ../compat
69+
$ export LD_LIBRARY_PATH=../build/blosc
70+
$ gcc -o filegen-vl filegen-vl.c -L$LD_LIBRARY_PATH -lblosc2 -I../include
71+
$ ./filegen-vl compress lz4 vlblocks-lz4-fixed-2.y.z.b2frame
72+
$ ./filegen-vl compress lz4 vlblocks-lz4-variable-2.y.z.b2frame --variable-chunks
73+
74+
Then, build ``compat/filegen-vl`` against the target Blosc library and check
75+
the fixtures with::
76+
77+
$ ./filegen-vl decompress vlblocks-lz4-fixed-2.y.z.b2frame
78+
$ ./filegen-vl decompress vlblocks-lz4-variable-2.y.z.b2frame
79+
80+
Expected results:
81+
82+
* These VL-block fixtures are only expected to work with releases that support
83+
the VL-block cframe format.
84+
* Pre-vlblocks releases are expected to reject them.
85+
6086
Tagging
6187
-------
6288

blosc/frame.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void *new_header_frame(blosc2_schunk *schunk, blosc2_frame_s *frame) {
113113
return NULL;
114114
}
115115
// General flags
116-
if (schunk->flags2 & BLOSC2_VL_BLOCKS) {
116+
if (schunk->chunksize == 0 || (schunk->flags2 & BLOSC2_VL_BLOCKS)) {
117117
*h2p = BLOSC2_VERSION_FRAME_FORMAT_VL_BLOCKS; // version
118118
}
119119
else {
@@ -418,6 +418,11 @@ int get_header_info(blosc2_frame_s *frame, int32_t *header_len, int64_t *frame_l
418418

419419
// Consistency check for frame type
420420
uint8_t frame_type = framep[FRAME_TYPE];
421+
uint8_t frame_version = framep[FRAME_FLAGS] & 0x0fu;
422+
if (frame_version > BLOSC2_VERSION_FRAME_FORMAT) {
423+
BLOSC_TRACE_ERROR("Unsupported cframe version: %u", frame_version);
424+
return BLOSC2_ERROR_VERSION_SUPPORT;
425+
}
421426
if (frame->sframe) {
422427
if (frame_type != FRAME_DIRECTORY_TYPE) {
423428
return BLOSC2_ERROR_FRAME_TYPE;
@@ -1115,7 +1120,7 @@ int64_t frame_from_schunk(blosc2_schunk *schunk, blosc2_frame_s *frame) {
11151120
else {
11161121
h2[FRAME_FLAGS] &= (uint8_t)~FRAME_VARIABLE_CHUNKS;
11171122
}
1118-
if (schunk->flags2 & BLOSC2_VL_BLOCKS) {
1123+
if (schunk->chunksize == 0 || (schunk->flags2 & BLOSC2_VL_BLOCKS)) {
11191124
h2[FRAME_FLAGS] = (uint8_t)((h2[FRAME_FLAGS] & (uint8_t)~0x0fu) | BLOSC2_VERSION_FRAME_FORMAT_VL_BLOCKS);
11201125
h2[FRAME_FLAGS] |= FRAME_VL_BLOCKS;
11211126
}

compat/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ add_executable(filegen filegen.c)
44
target_link_libraries(filegen blosc_testing)
55
add_dependencies(filegen blosc_testing)
66

7+
add_executable(filegen-vl filegen-vl.c)
8+
target_link_libraries(filegen-vl blosc_testing)
9+
add_dependencies(filegen-vl blosc_testing)
10+
711
# tests
812
if(BUILD_TESTS)
913
option(TEST_INCLUDE_COMPAT "Include compat checks in the tests" ON)

0 commit comments

Comments
 (0)