|
|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
- * Copyright (C) 2007-2022 Siemens AG
|
|
|
+ * Copyright (C) 2007-2025 Siemens AG
|
|
|
*
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
* it under the terms of the GNU Lesser General Public License as published
|
|
|
@@ -18,7 +18,7 @@
|
|
|
/*******************************************************************
|
|
|
*
|
|
|
* @author Daniel.Peintner.EXT@siemens.com
|
|
|
- * @version 2022-03-08
|
|
|
+ * @version 2025-01-14
|
|
|
* @contact Richard.Kuntschke@siemens.com
|
|
|
*
|
|
|
* <p>Code generated by EXIdizer</p>
|
|
|
@@ -36,7 +36,7 @@
|
|
|
#include "BitInputStream.h"
|
|
|
#include "EXITypes.h"
|
|
|
#include "MethodsBag.h"
|
|
|
-/*#include "v2gEXICoder.h"*/
|
|
|
+/*#include "EXICoder.h"*/
|
|
|
#include "ErrorCodes.h"
|
|
|
|
|
|
#if MEMORY_ALLOCATION == DYNAMIC_ALLOCATION
|
|
|
@@ -173,6 +173,9 @@ int decodeUnsignedInteger16(bitstream_t* stream, uint16_t* uint16) {
|
|
|
do {
|
|
|
/* 1. Read the next octet */
|
|
|
errn = decode(stream, &b);
|
|
|
+ if ((8 - numberOfLeadingZeros((b & 127)) + mShift) > 16) {
|
|
|
+ return EXI_ERROR_INTEGER_OVERFLOW;
|
|
|
+ }
|
|
|
/* 2. Multiply the value of the unsigned number represented by the 7
|
|
|
* least significant
|
|
|
* bits of the octet by the current multiplier and add the result to
|
|
|
@@ -196,6 +199,9 @@ int decodeUnsignedInteger32(bitstream_t* stream, uint32_t* uint32) {
|
|
|
do {
|
|
|
/* 1. Read the next octet */
|
|
|
errn = decode(stream, &b);
|
|
|
+ if ((8 - numberOfLeadingZeros((b & 127)) + mShift) > 32) {
|
|
|
+ return EXI_ERROR_INTEGER_OVERFLOW;
|
|
|
+ }
|
|
|
/* 2. Multiply the value of the unsigned number represented by the 7
|
|
|
* least significant
|
|
|
* bits of the octet by the current multiplier and add the result to
|
|
|
@@ -250,11 +256,14 @@ int decodeUnsignedIntegerSizeT(bitstream_t* stream, size_t* sizeT) {
|
|
|
int decodeUnsignedInteger64(bitstream_t* stream, uint64_t* uint64) {
|
|
|
unsigned int mShift = 0;
|
|
|
int errn = 0;
|
|
|
- uint8_t b;
|
|
|
+ uint8_t b = 0;
|
|
|
*uint64 = 0L;
|
|
|
|
|
|
do {
|
|
|
errn = decode(stream, &b);
|
|
|
+ if ((8 - numberOfLeadingZeros((b & 127)) + mShift) > 64) {
|
|
|
+ return EXI_ERROR_INTEGER_OVERFLOW;
|
|
|
+ }
|
|
|
*uint64 += ((uint64_t) (b & 127)) << mShift;
|
|
|
mShift += 7;
|
|
|
} while (errn == 0 && (b >> 7) == 1);
|
|
|
@@ -262,7 +271,6 @@ int decodeUnsignedInteger64(bitstream_t* stream, uint64_t* uint64) {
|
|
|
return errn;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
void _reverseArray(uint8_t *array, int number) {
|
|
|
int x, t;
|
|
|
number--;
|
|
|
@@ -577,6 +585,7 @@ int decodeUnsignedIntegerBig(bitstream_t* stream, size_t size, uint8_t* data, si
|
|
|
return errn;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
int decodeInteger(bitstream_t* stream, exi_integer_t* iv) {
|
|
|
int b;
|
|
|
int errn = decodeBoolean(stream, &b);
|
|
|
@@ -600,15 +609,29 @@ int decodeInteger16(bitstream_t* stream, int16_t* int16) {
|
|
|
int errn = decodeBoolean(stream, &b);
|
|
|
|
|
|
if (errn == 0) {
|
|
|
+ /* INT16_MIN -32768 */
|
|
|
+ /* INT16_MAX 32767 */
|
|
|
if (b) {
|
|
|
/* For negative values, the Unsigned Integer holds the
|
|
|
* magnitude of the value minus 1 */
|
|
|
errn = decodeUnsignedInteger16(stream, &uint16);
|
|
|
- *int16 = (int16_t)(-(uint16 + 1));
|
|
|
+ if (errn == 0) {
|
|
|
+ if (uint16 < 32768) {
|
|
|
+ *int16 = (int16_t)(-(uint16 + 1));
|
|
|
+ } else {
|
|
|
+ errn = EXI_ERROR_INTEGER_OVERFLOW;
|
|
|
+ }
|
|
|
+ }
|
|
|
} else {
|
|
|
/* positive */
|
|
|
errn = decodeUnsignedInteger16(stream, &uint16);
|
|
|
- *int16 = (int16_t)(uint16);
|
|
|
+ if (errn == 0) {
|
|
|
+ if (uint16 <= 32767) {
|
|
|
+ *int16 = (int16_t)(uint16);
|
|
|
+ } else {
|
|
|
+ errn = EXI_ERROR_INTEGER_OVERFLOW;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -627,15 +650,31 @@ int decodeInteger32(bitstream_t* stream, int32_t* int32) {
|
|
|
int errn = decodeBoolean(stream, &b);
|
|
|
|
|
|
if (errn == 0) {
|
|
|
+ /* INT16_MIN -2147483648 */
|
|
|
+ /* INT16_MAX 2147483647 */
|
|
|
if (b) {
|
|
|
/* For negative values, the Unsigned Integer holds the
|
|
|
* magnitude of the value minus 1 */
|
|
|
errn = decodeUnsignedInteger32(stream, &uint32);
|
|
|
- *int32 = (-(int32_t)(uint32 + 1));
|
|
|
+ if (errn == 0) {
|
|
|
+ /* INT32_MIN (-2147483647 - 1) */
|
|
|
+ if ((uint32-1) < 2147483647) {
|
|
|
+ *int32 = (-(int32_t)(uint32 + 1));
|
|
|
+ } else {
|
|
|
+ errn = EXI_ERROR_INTEGER_OVERFLOW;
|
|
|
+ }
|
|
|
+ }
|
|
|
} else {
|
|
|
/* positive */
|
|
|
errn = decodeUnsignedInteger32(stream, &uint32);
|
|
|
- *int32 = (int32_t)(uint32);
|
|
|
+ if (errn == 0) {
|
|
|
+ /* INT32_MAX 2147483647 */
|
|
|
+ if (uint32 <= 2147483647) {
|
|
|
+ *int32 = (int32_t)(uint32);
|
|
|
+ } else {
|
|
|
+ errn = EXI_ERROR_INTEGER_OVERFLOW;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -658,11 +697,25 @@ int decodeInteger64(bitstream_t* stream, int64_t* int64) {
|
|
|
/* For negative values, the Unsigned Integer holds the
|
|
|
* magnitude of the value minus 1 */
|
|
|
errn = decodeUnsignedInteger64(stream, &uint64);
|
|
|
- *int64 = (-(int64_t)(uint64 + 1));
|
|
|
+ if (errn == 0) {
|
|
|
+ /* INT64_MIN (-9223372036854775807LL - 1)*/
|
|
|
+ if ((uint64-1) < 9223372036854775807LL) {
|
|
|
+ *int64 = (-(int64_t)(uint64 + 1));
|
|
|
+ } else {
|
|
|
+ errn = EXI_ERROR_INTEGER_OVERFLOW;
|
|
|
+ }
|
|
|
+ }
|
|
|
} else {
|
|
|
/* positive */
|
|
|
errn = decodeUnsignedInteger64(stream, &uint64);
|
|
|
- *int64 = (int64_t)(uint64);
|
|
|
+ if (errn == 0) {
|
|
|
+ /** INT64_MAX 9223372036854775807LL */
|
|
|
+ if (uint64 <= 9223372036854775807LL) {
|
|
|
+ *int64 = (int64_t)(uint64);
|
|
|
+ } else {
|
|
|
+ errn = EXI_ERROR_INTEGER_OVERFLOW;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|