Skip to content

[C#] Fix incorrect offset type in verifier (https://github.com/google/flatbuffers/issues/8937) - #9242

Open
stefan301 wants to merge 7 commits into
google:masterfrom
stefan301:master
Open

stefan301 wants to merge 7 commits into
google:masterfrom
stefan301:master

Conversation

@stefan301

Copy link
Copy Markdown
Contributor

[C#] Fix incorrect offset type in verifier (#8937)

This is a fix for private short GetVRelOffset(int pos, short vtableOffset), which doesn't calculate the vtable position correctly.
Instead of
short vtable = Convert.ToInt16(pos - ReadSOffsetT(verifier_buffer, pos));
it should be
int vtable = pos - ReadSOffsetT(verifier_buffer, pos);

I added the Test TestVerifyingTableWithRelativeOffsetAbove32k, which failed without the fix:

D:\github\stefan301\flatbuffers\tests>D:\github\stefan301\flatbuffers\tests\FlatBuffers.Test\bin\Debug\net8.0\FlatBuffers.Test.exe
...
Exception: System.OverflowException: Value was either too large or too small for an Int16.
at System.Convert.ThrowInt16OverflowException()
at System.Convert.ToInt16(Int32 value)
at Google.FlatBuffers.Verifier.GetVRelOffset(Int32 pos, Int16 vtableOffset) in D:\github\stefan301\flatbuffers\net\FlatBuffers\FlatBufferVerify.cs:line 243
FlatBuffersExampleTests: FAILED when invoking TestVerifyingTableWithRelativeOffsetAbove32k with error Google.FlatBuffers.Test.AssertFailedException: Expected True but saw False
at Google.FlatBuffers.Test.Assert.AreEqual[T](T expected, T actual) in D:\github\stefan301\flatbuffers\tests\FlatBuffers.Test\Assert.cs:line 82
at Google.FlatBuffers.Test.FlatBuffersExampleTests.TestVerifyingTableWithRelativeOffsetAbove32k() in D:\github\stefan301\flatbuffers\tests\FlatBuffers.Test\FlatBuffersExampleTests.cs:line 1259
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
157 tests run, 1 failed

with the fix, all Tests succeed:

D:\github\stefan301\flatbuffers\tests>D:\github\stefan301\flatbuffers\tests\FlatBuffers.Test\bin\Debug\net8.0\FlatBuffers.Test.exe157 tests run, 0 failed

stefan301 and others added 7 commits January 21, 2026 12:56
__vector_as_array<T> calling ByteBuffer.ToArray<T> with the length in bytes by multiplying len with ByteBuffer.Sizeof<T> and FlatBuffersExampleTests extended to call GetVectorOfLongsArray/GetVectorOfDoublesArray which failed without the fix
add --format sln to the dotnet new command, maybe it is currently creating a .slnx instead?
- Test TestVerifyingTableWithRelativeOffsetAbove32k added, which failed without the fix
- Fix Verifier.GetVRelOffset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants