From 5cc069fedfd8453c24490095fc59e5d826251d40 Mon Sep 17 00:00:00 2001 From: Jerome Haltom Date: Mon, 28 Oct 2024 16:54:18 -0500 Subject: [PATCH] Added some tests for larger files. Examined needs to be the entire buffer. --- .../Decoding/ClassFileTests.cs | 16 ++++++++++++++++ .../Decoding/large-module-info.class | Bin 0 -> 4619 bytes .../IKVM.ByteCode.Tests.csproj | 6 ------ src/IKVM.ByteCode/Decoding/ClassFile.cs | 11 +++++------ 4 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 src/IKVM.ByteCode.Tests/Decoding/large-module-info.class 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 0000000000000000000000000000000000000000..1bc3a7f5d4d9cb004a63994756e4417989629558 GIT binary patch literal 4619 zcmbW5=X=yf5Ql$DiXn6)dg#4a!ls1)q1c8HaBu<%A%u`UoowqYX@#Ua&ZLpvd+)vX zo{;)Ee^j1~Msjd?Z0{L=cyG0u8ST!_?9Te{f6o2^U?ct#7$2x|)pwh{uv;}j2+UJ) zk0m4N^tzU>dV0LDC;Qz{u^bh<1}+k~wAE@|Z?)vIb}nldvf1y3ik-=txKv;{nHye& z-b8L#c4HG`1y(gCYnMwVE)%dC7Pl+ql4D|m!0HBd0u`8;B+$~hyj^i)6`V9NMPS`1 z)cRz1pENN|U~Pk1p-N8rCd|fN5WA;hFQpZkF$x{!`?UBbW(jO;aAa|=V@oIXRA^$( zXg*g>`E!>GEYW-}=?`f+=L;+ySb!Zrm?3zbG!KzmZ*o_S#RuQe1=hFAK39M;IDM@8o zC55X5RyL$i4`^|AHX5q^G85me&FgN@rz|zmt_|v3(hjPrEcvwm?Gac!^1$tXrWI~npy#f>Ykqkth?~*s}7ns0Z zWjE2dxQ(vd4JXd-wJFS*;aOR+J}2%SC)sI^7jJm z!&)egokG988bqD>L9{ftxQ{NVdnj8}+~0&B1$GQ;DNA{Kz+6W?%`TYbA&mSy(%F$j zUgpSRvCe9513dQw+1>Y?)^BuG?&Rw=wlO=Hdzt%~`z(2Pyfc*j4jxT?bv}`XhR3~VjuRS69;h}4&eqI!BHH; Sah!mJ0~bB;(1!pDC;tU>*L}zU literal 0 HcmV?d00001 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; } }