diff options
| author | Stefan Boberg <[email protected]> | 2025-05-16 12:08:05 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2025-05-16 13:08:05 +0200 |
| commit | 95fc783ae9914019fee03f12603e4c49f9ab6106 (patch) | |
| tree | 0ab24bc40ac893c0a2428254145c8ffaec5ec044 | |
| parent | sparse win file write (#398) (diff) | |
| download | zen-95fc783ae9914019fee03f12603e4c49f9ab6106.tar.xz zen-95fc783ae9914019fee03f12603e4c49f9ab6106.zip | |
validate custom fields (#399)
* implemented validation of compact binary custom fields
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | src/zencore/compactbinaryvalidation.cpp | 45 |
2 files changed, 45 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 712cb2edc..6290974a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - Feature: Added `--use-sparse-files` option to `zen builds` command improving write performance of large files. Enabled by default. - Bugfix: Handle invalid plugin config file without terminating - Bugfix: Gracefully handle errors while running `oplog-mirror` +- Bugfix: Implemented compact binary validation of custom fields - Improvement: `--cache-memlayer-sizethreshold` is now deprecated and has a new name: `--cache-bucket-memlayer-sizethreshold` to line up with per cache bucket configuration - Improvement: Remove CAS log files at startup when we write full state index - Improvement: Optimize memory-buffered chunk iteration sizes diff --git a/src/zencore/compactbinaryvalidation.cpp b/src/zencore/compactbinaryvalidation.cpp index 6f53bba69..833649b88 100644 --- a/src/zencore/compactbinaryvalidation.cpp +++ b/src/zencore/compactbinaryvalidation.cpp @@ -135,6 +135,37 @@ ValidateCbFloat64(MemoryView& View, CbValidateMode Mode, CbValidateError& Error) } /** + * Validate and read a fixed-size value from the view. + * + * Modifies the view to start at the end of the value, and adds error flags if applicable. + */ +static MemoryView +ValidateCbFixedValue(MemoryView& View, CbValidateMode Mode, CbValidateError& Error, uint64_t Size) +{ + ZEN_UNUSED(Mode); + + const MemoryView Value = View.Left(Size); + View += Size; + if (Value.GetSize() < Size) + { + AddError(Error, CbValidateError::OutOfBounds); + } + return Value; +}; + +/** + * Validate and read a value from the view where the view begins with the value size. + * + * Modifies the view to start at the end of the value, and adds error flags if applicable. + */ +static MemoryView +ValidateCbDynamicValue(MemoryView& View, CbValidateMode Mode, CbValidateError& Error) +{ + const uint64_t ValueSize = ValidateCbUInt(View, Mode, Error); + return ValidateCbFixedValue(View, Mode, Error, ValueSize); +} + +/** * Validate and read a string from the view. * * Modifies the view to start at the end of the string, and adds error flags if applicable. @@ -378,8 +409,20 @@ ValidateCbField(MemoryView& View, CbValidateMode Mode, CbValidateError& Error, c ValidateFixedPayload(12); break; case CbFieldType::CustomById: + { + MemoryView Value = ValidateCbDynamicValue(View, Mode, Error); + ValidateCbUInt(Value, Mode, Error); + } + break; case CbFieldType::CustomByName: - ZEN_NOT_IMPLEMENTED(); // TODO: FIX! + { + MemoryView Value = ValidateCbDynamicValue(View, Mode, Error); + const std::string_view TypeName = ValidateCbString(Value, Mode, Error); + if (TypeName.empty() && !EnumHasAnyFlags(Error, CbValidateError::OutOfBounds)) + { + AddError(Error, CbValidateError::InvalidType); + } + } break; } |