Skip to content

Commit

Permalink
Add check for stored sizes in parsing (#103)
Browse files Browse the repository at this point in the history
* added enum constant and check for stored sizes for dims other than x,y,m.

* added to lax parsing.

* clean-up.

* clean-up and review comments.

* ouput corrected.

* added unit test, output correction

* updated version.

* added entry for verison history.

* changed test data to restore test coverage.
  • Loading branch information
sdierg committed Jun 20, 2024
1 parent 067f3b0 commit dedfa6e
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.15)
cmake_policy(SET CMP0091 NEW) # enable new "MSVC runtime library selection" (https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html)

project(libCZI
VERSION 0.58.4
VERSION 0.59.0
HOMEPAGE_URL "https://github.com/ZEISS/libczi"
DESCRIPTION "libCZI is an Open Source Cross-Platform C++ library to read and write CZI")

Expand Down
15 changes: 15 additions & 0 deletions Src/libCZI/CziParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,21 @@ using namespace libCZI;
{
libCZI::DimensionIndex dim = CCZIParse::DimensionCharToDimensionIndex(subBlkDirDV->DimensionEntries[i].Dimension, 4);
entry.coordinate.Set(dim, subBlkDirDV->DimensionEntries[i].Start);

if(options.GetPhysicalDimensionOtherThanMMustHaveSizeOne())
{
auto physicalSize = subBlkDirDV->DimensionEntries[i].StoredSize;
if(physicalSize != 1)
{
stringstream string_stream;
string_stream
<< "Physical size for dimension '" << Utils::DimensionToChar(dim)
<< "' is expected to be 1, but found " << physicalSize
<< " (file-offset:" << subBlkDirDV->FilePosition << ").";
throw LibCZICZIParseException(string_stream.str().c_str(), LibCZICZIParseException::ErrorCode::NonConformingSubBlockDimensionEntry);
}
}

if (options.GetDimensionOtherThanMMustHaveSizeOne() && subBlkDirDV->DimensionEntries[i].Size != 1)
{
stringstream string_stream;
Expand Down
15 changes: 14 additions & 1 deletion Src/libCZI/CziParse.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class CCZIParse
{
kDimensionXyMustBePresent = 0,
kDimensionOtherThanMMustHaveSizeOne,
kPhysicalDimensionOtherThanMMustHaveSizeOne,
kDimensionMMustHaveSizeOneExceptForPyramidSubblocks,
kDimensionMMustHaveSizeOne,

Expand All @@ -45,11 +46,16 @@ class CCZIParse
/// \param enable True to enable, false to disable.
void SetDimensionXyMustBePresent(bool enable) { return this->SetFlag(ParseFlags::kDimensionXyMustBePresent, enable); }

/// Require that for each subblock the physical size (for all dimensions other than X, Y and M) is "1".
///
/// \param enable True to enable, false to disable.
void SetPhysicalDimensionOtherThanMMustHaveSizeOne(bool enable) { return this->SetFlag(ParseFlags::kPhysicalDimensionOtherThanMMustHaveSizeOne, enable); }

/// Require that for each subblock the size (for all dimensions other than X, Y and M) is "1".
///
/// \param enable True to enable, false to disable.
void SetDimensionOtherThanMMustHaveSizeOne(bool enable) { return this->SetFlag(ParseFlags::kDimensionOtherThanMMustHaveSizeOne, enable); }

void SetDimensionOtherThanMMustHaveSizeOne(bool enable) { return this->SetFlag(ParseFlags::kDimensionOtherThanMMustHaveSizeOne, enable); }
/// Require that for all subblocks that the size of dimension M is "1" except for pyramid subblocks.
///
/// \param enable True to enable, false to disable.
Expand All @@ -70,6 +76,11 @@ class CCZIParse
/// \returns True if it is to be checked that the size of all dimensions other than X, Y and M is "1" for each subblock; false otherwise.
bool GetDimensionOtherThanMMustHaveSizeOne() const { return this->GetFlag(ParseFlags::kDimensionOtherThanMMustHaveSizeOne); }

/// Gets a boolean indicating whether to check that the physical size of all dimensions other than X, Y and M is "1" for each subblock.
///
/// \returns True if it is to be checked that the physical size of all dimensions other than X, Y and M is "1" for each subblock; false otherwise.
bool GetPhysicalDimensionOtherThanMMustHaveSizeOne() const { return this->GetFlag(ParseFlags::kPhysicalDimensionOtherThanMMustHaveSizeOne); }

/// Gets a boolean indicating whether to check that the size is "1" for dimension M for all non-pyramid-subblocks.
/// This flag is more specific than the flag "DimensionMMustHaveSizeOne".
///
Expand All @@ -86,13 +97,15 @@ class CCZIParse
{
this->SetDimensionXyMustBePresent(false);
this->SetDimensionOtherThanMMustHaveSizeOne(false);
this->SetPhysicalDimensionOtherThanMMustHaveSizeOne(false);
this->SetDimensionMMustHaveSizeOne(false);
}

/// Sets strict parsing - all options are enabled.
void SetStrictParsing()
{
this->SetDimensionXyMustBePresent(true);
this->SetPhysicalDimensionOtherThanMMustHaveSizeOne(true);
this->SetDimensionOtherThanMMustHaveSizeOne(true);
this->SetDimensionMMustHaveSizeOne(true);
}
Expand Down
3 changes: 2 additions & 1 deletion Src/libCZI/Doc/version-history.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ version history {#version_history}
0.58.1 | [95](https://github.com/ZEISS/libczi/pull/95) | some fixes for CziReaderWriter
0.58.2 | [96](https://github.com/ZEISS/libczi/pull/96) | small fixes for deficiencies reported by CodeQL
0.58.3 | [97](https://github.com/ZEISS/libczi/pull/97) | update zstd to [version 1.5.6](https://github.com/facebook/zstd/releases/tag/v1.5.6)
0.58.4 | [99](https://github.com/ZEISS/libczi/pull/99) | fix a rare issue with curl_http_inputstream which would fail to read CZIs with an attachment-directory containing zero entries
0.58.4 | [99](https://github.com/ZEISS/libczi/pull/99) | fix a rare issue with curl_http_inputstream which would fail to read CZIs with an attachment-directory containing zero entries
0.59.0 | [99](https://github.com/ZEISS/libczi/pull/103) | add a check for physical size for dimensions other than X,Y,M, they must not be >1, active for strict parsing.
Loading

0 comments on commit dedfa6e

Please sign in to comment.