diff options
author | phenixxy <phenix.xia@gmail.com> | 2023-03-24 11:15:34 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-24 03:15:34 +0000 |
commit | 1cb1c4baeeedfe3bc90d8c4110c889dd17af5ca7 (patch) | |
tree | 1d312fa5c84afc0f741ba54ae25750bbf3b326f3 | |
parent | 50cdf92e1ef4182f9e6174eebd3d930221617613 (diff) | |
download | flatbuffers-1cb1c4baeeedfe3bc90d8c4110c889dd17af5ca7.tar.gz flatbuffers-1cb1c4baeeedfe3bc90d8c4110c889dd17af5ca7.tar.bz2 flatbuffers-1cb1c4baeeedfe3bc90d8c4110c889dd17af5ca7.zip |
fix using null string in vector (#7872)
Use 0 offset as special value. 0 offset is not a valid relative offset, so it's safe to use 0 offset to indicate value is null.
https://github.com/google/flatbuffers/issues/7846
-rw-r--r-- | net/FlatBuffers/FlatBufferBuilder.cs | 3 | ||||
-rw-r--r-- | net/FlatBuffers/Table.cs | 6 |
2 files changed, 7 insertions, 2 deletions
diff --git a/net/FlatBuffers/FlatBufferBuilder.cs b/net/FlatBuffers/FlatBufferBuilder.cs index e550f90f..e08db847 100644 --- a/net/FlatBuffers/FlatBufferBuilder.cs +++ b/net/FlatBuffers/FlatBufferBuilder.cs @@ -438,7 +438,8 @@ namespace Google.FlatBuffers if (off > Offset) throw new ArgumentException(); - off = Offset - off + sizeof(int); + if (off != 0) + off = Offset - off + sizeof(int); PutInt(off); } diff --git a/net/FlatBuffers/Table.cs b/net/FlatBuffers/Table.cs index 21ef7dc8..2aaa86e9 100644 --- a/net/FlatBuffers/Table.cs +++ b/net/FlatBuffers/Table.cs @@ -65,7 +65,11 @@ namespace Google.FlatBuffers // Create a .NET String from UTF-8 data stored inside the flatbuffer. public string __string(int offset) { - offset += bb.GetInt(offset); + int stringOffset = bb.GetInt(offset); + if (stringOffset == 0) + return null; + + offset += stringOffset; var len = bb.GetInt(offset); var startPos = offset + sizeof(int); return bb.GetStringUTF8(startPos, len); |