diff --git a/src/IKVM.ByteCode.Tests/Decoding/ClassFileTests.cs b/src/IKVM.ByteCode.Tests/Decoding/ClassFileTests.cs index 2752a0c..8ddab7a 100644 --- a/src/IKVM.ByteCode.Tests/Decoding/ClassFileTests.cs +++ b/src/IKVM.ByteCode.Tests/Decoding/ClassFileTests.cs @@ -279,6 +279,22 @@ void TestElementValue(ClassFile clazz, ArrayElementValue value) TestElementValue(clazz, elementValue); } + [TestMethod] + public void CanReadFromLargeModuleInfo() + { + using var clazz = ClassFile.Read(Path.Combine(Path.GetDirectoryName(typeof(ClassFileTests).Assembly.Location), "Decoding", "large-module-info.class")); + clazz.Should().NotBeNull(); + } + + [TestMethod] + public void CanReadFromLargeModuleInfoFromStream() + { + var buf = File.ReadAllBytes(Path.Combine(Path.GetDirectoryName(typeof(ClassFileTests).Assembly.Location), "Decoding", "large-module-info.class")); + var stm = new MemoryStream(buf); + using var clazz = ClassFile.Read(stm); + clazz.Should().NotBeNull(); + } + } } diff --git a/src/IKVM.ByteCode.Tests/Decoding/large-module-info.class b/src/IKVM.ByteCode.Tests/Decoding/large-module-info.class new file mode 100644 index 0000000..1bc3a7f Binary files /dev/null and b/src/IKVM.ByteCode.Tests/Decoding/large-module-info.class differ diff --git a/src/IKVM.ByteCode.Tests/IKVM.ByteCode.Tests.csproj b/src/IKVM.ByteCode.Tests/IKVM.ByteCode.Tests.csproj index 3e6d61f..697e133 100644 --- a/src/IKVM.ByteCode.Tests/IKVM.ByteCode.Tests.csproj +++ b/src/IKVM.ByteCode.Tests/IKVM.ByteCode.Tests.csproj @@ -5,12 +5,6 @@ true - - - - - - diff --git a/src/IKVM.ByteCode/Decoding/ClassFile.cs b/src/IKVM.ByteCode/Decoding/ClassFile.cs index bc9ad65..c972fd8 100644 --- a/src/IKVM.ByteCode/Decoding/ClassFile.cs +++ b/src/IKVM.ByteCode/Decoding/ClassFile.cs @@ -192,20 +192,19 @@ public static bool TryMeasure(in ReadOnlySequence buffer, ref int size, ou /// public static bool TryRead(in ReadOnlySequence buffer, out ClassFile? clazz, out SequencePosition consumed, out SequencePosition examined, IMemoryOwner? owner = null) { - consumed = buffer.Start; - var reader = new ClassFormatReader(buffer); if (TryRead(ref reader, out clazz, owner) == false) { - // examined up to the position of the reader, but consumed nothing - examined = reader.Position; + // examined up to the end of the buffer, but consumed nothing + examined = buffer.End; + consumed = buffer.Start; return false; } else { - // examined up to the point of the reader, consumed the same + // examined up to the end of thebuffer, but consumed up until the position of the reader + examined = buffer.End; consumed = reader.Position; - examined = reader.Position; return true; } }