dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.45k stars 4.76k forks source link

'0x00' is an invalid start of a value. #87036

Closed BABAYEGAR closed 1 year ago

BABAYEGAR commented 1 year ago

Description

This occurs when i try to parse very large complex json, using the JsonObject.Parse() from a file stream.

An exception is thrown as seen System.Text.Json.JsonException: '0x00' is an invalid start of a value.

I expect the json to be parsed regardless of the null trailing values

Configuration

.NET 6
Linux
x64
It works perfectly on windows but fails on Linux

Regression?

Not sure it did, a new feature i am working on uses large json so that's where i discovered the error

Other information

Exception: System.Text.Json.JsonException: '0x00' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0. ---> System.Text.Json.JsonReaderException: '0x00' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0. at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes) at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte marker) at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte first) at System.Text.Json.Utf8JsonReader.ReadSingleSegment() at System.Text.Json.Utf8JsonReader.Read() at System.Text.Json.JsonSerializer.ReadCore(JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& readStack) --- End of inner exception stack trace --- at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& readStack, JsonReaderException ex) at System.Text.Json.JsonSerializer.ReadCore(JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& readStack) at System.Text.Json.JsonSerializer.ReadCore(Type returnType, JsonSerializerOptions options, Utf8JsonReader& reader) at System.Text.Json.JsonSerializer.Deserialize(String json, Type returnType, JsonSerializerOptions options) at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options) at PowerLauncher.SettingsWatcher.OverloadSettings() at PowerLauncher.SettingsWatcher..ctor(Settings settings) at PowerLauncher.App.<>c__DisplayClass16_0.b1() at Wox.Infrastructure.Stopwatch.Normal(String message, Action action) at PowerLauncher.App.OnStartup(Object sender, StartupEventArgs e) at System.Windows.Application.OnStartup(StartupEventArgs e) at System.Windows.Application.<.ctor>b1_0(Object unused) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

Seems like Newtonsoft handles such scenario correctly. But i prefer system.text.json as it is more efficient.

BABAYEGAR commented 1 year ago

OS info: Amazon Linux 2 | x86_64, arm64

ghost commented 1 year ago

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis See info in area-owners.md if you want to be subscribed.

Issue Details
### Description `This occurs when i try to parse very large complex json, using the JsonObject.Parse() from a file stream.` ``` An exception is thrown as seen System.Text.Json.JsonException: '0x00' is an invalid start of a value. I expect the json to be parsed regardless of the null trailing values ``` ### Configuration ``` .NET 6 Linux x64 It works perfectly on windows but fails on Linux ``` ### Regression? `Not sure it did, a new feature i am working on uses large json so that's where i discovered the error` ### Other information Exception: System.Text.Json.JsonException: '0x00' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0. ---> System.Text.Json.JsonReaderException: '0x00' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0. at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes) at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte marker) at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte first) at System.Text.Json.Utf8JsonReader.ReadSingleSegment() at System.Text.Json.Utf8JsonReader.Read() at System.Text.Json.JsonSerializer.ReadCore(JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& readStack) --- End of inner exception stack trace --- at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& readStack, JsonReaderException ex) at System.Text.Json.JsonSerializer.ReadCore(JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& readStack) at System.Text.Json.JsonSerializer.ReadCore(Type returnType, JsonSerializerOptions options, Utf8JsonReader& reader) at System.Text.Json.JsonSerializer.Deserialize(String json, Type returnType, JsonSerializerOptions options) at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options) at PowerLauncher.SettingsWatcher.OverloadSettings() at PowerLauncher.SettingsWatcher..ctor(Settings settings) at PowerLauncher.App.<>c__DisplayClass16_0.b__1() at Wox.Infrastructure.Stopwatch.Normal(String message, Action action) at PowerLauncher.App.OnStartup(Object sender, StartupEventArgs e) at System.Windows.Application.OnStartup(StartupEventArgs e) at System.Windows.Application.<.ctor>b__1_0(Object unused) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) `Seems like Newtonsoft handles such scenario correctly. But i prefer system.text.json as it is more efficient.`
Author: BABAYEGAR
Assignees: -
Labels: `area-System.Text.Json`, `untriaged`
Milestone: -
danmoseley commented 1 year ago

Can you share the part of the json that is causing this? Ideally reduce your json file down to just the minimum necessary to still make it fail

eiriktsarpalis commented 1 year ago

This is by-design, but we have an issue tracking potentially tolerating invalid data:

https://github.com/dotnet/runtime/issues/32291

BABAYEGAR commented 1 year ago

Hi @danmoseley Honestly its a very very large JSON for about 3MB worth of data. Its super hard to know where the error is from. The json contains excel spreadsheet data and structure but when i paste the json in a json formatter it says the json structure is valid and the error never appears on a windows machine too

danmoseley commented 1 year ago

No problem, it looks like the team knows the issue, per above.