aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/compactbinaryvalidation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zencore/compactbinaryvalidation.cpp')
-rw-r--r--src/zencore/compactbinaryvalidation.cpp27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/zencore/compactbinaryvalidation.cpp b/src/zencore/compactbinaryvalidation.cpp
index db830d250..82738e678 100644
--- a/src/zencore/compactbinaryvalidation.cpp
+++ b/src/zencore/compactbinaryvalidation.cpp
@@ -86,23 +86,24 @@ ValidateCbFieldType(MemoryView& View, CbValidateMode Mode, CbValidateError& Erro
static uint64_t
ValidateCbUInt(MemoryView& View, CbValidateMode Mode, CbValidateError& Error)
{
- if (View.GetSize() > 0 && View.GetSize() >= MeasureVarUInt(View.GetData()))
+ size_t ViewSize = View.GetSize();
+ if (ViewSize > 0)
{
- uint32_t ValueByteCount;
- const uint64_t Value = ReadVarUInt(View.GetData(), ValueByteCount);
- if (EnumHasAnyFlags(Mode, CbValidateMode::Format) && ValueByteCount > MeasureVarUInt(Value))
+ uint32_t ValueByteCount = MeasureVarUInt(View.GetData());
+ if (ViewSize >= ValueByteCount)
{
- AddError(Error, CbValidateError::InvalidInteger);
+ const uint64_t Value = ReadMeasuredVarUInt(View.GetData(), ValueByteCount);
+ if (EnumHasAnyFlags(Mode, CbValidateMode::Format) && ValueByteCount != MeasureVarUInt(Value))
+ {
+ AddError(Error, CbValidateError::InvalidInteger);
+ }
+ View += ValueByteCount;
+ return Value;
}
- View += ValueByteCount;
- return Value;
- }
- else
- {
- AddError(Error, CbValidateError::OutOfBounds);
- View.Reset();
- return 0;
}
+ AddError(Error, CbValidateError::OutOfBounds);
+ View.Reset();
+ return 0;
}
/**