Skip to content

Commit acfd78e

Browse files
committed
bug #6: 0 and 17 are illegal values for PrimitiveType enum
1 parent a2a7a3f commit acfd78e

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/libraries/System.Formats.Nrbf/src/System/Formats/Nrbf/Utils/BinaryReaderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ internal static PrimitiveType ReadPrimitiveType(this BinaryReader reader)
6161
{
6262
byte primitiveType = reader.ReadByte();
6363
// String is the last defined value, 4 is not used at all.
64-
if (primitiveType is 4 or > (byte)PrimitiveType.String)
64+
if (primitiveType is 0 or 4 or (byte)PrimitiveType.Null or > (byte)PrimitiveType.String)
6565
{
6666
ThrowHelper.ThrowInvalidValue(primitiveType);
6767
}

src/libraries/System.Formats.Nrbf/tests/InvalidInputTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,9 @@ public static IEnumerable<object[]> ThrowsForInvalidPrimitiveType_Arguments()
426426
{
427427
foreach (byte binaryType in new byte[] { (byte)0 /* BinaryType.Primitive */, (byte)7 /* BinaryType.PrimitiveArray */ })
428428
{
429+
yield return new object[] { recordType, binaryType, (byte)0 }; // value not used by the spec
429430
yield return new object[] { recordType, binaryType, (byte)4 }; // value not used by the spec
431+
yield return new object[] { recordType, binaryType, (byte)17 }; // used by the spec, but illegal in given context
430432
yield return new object[] { recordType, binaryType, (byte)19 };
431433
}
432434
}

0 commit comments

Comments
 (0)