Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added check on length in deserialization of byte arrays #250

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/documentation/articles/serialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public class CustomKeySerDes<T> : SerDesRaw<T>
/// <inheritdoc cref="SerDes{T, TJVM}.DeserializeWithHeaders(string, Headers, TJVM)"/>
public override T DeserializeWithHeaders(string topic, Headers headers, byte[] data)
{
if (data == null) return default;
if (data == null || data.Length == 0) return default;
return System.Text.Json.JsonSerializer.Deserialize<T>(data)!;
}
}
Expand Down Expand Up @@ -230,7 +230,7 @@ public class CustomValueContainerSerDes<T> : SerDesRaw<T>
/// <inheritdoc cref="SerDes{T, TJVM}.DeserializeWithHeaders(string, Headers, TJVM)"/>
public override T DeserializeWithHeaders(string topic, Headers headers, byte[] data)
{
if (data == null) return default;
if (data == null || data.Length == 0) return default;
return System.Text.Json.JsonSerializer.Deserialize<T>(data)!;
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/net/KEFCore.SerDes.Avro/AvroKEFCoreSerDes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public override TData Deserialize(string topic, byte[] data)
public override TData DeserializeWithHeaders(string topic, Headers headers, byte[] data)
{
if (_defaultSerDes != null) return _defaultSerDes.DeserializeWithHeaders(topic, headers, data);
if (data == null || data.Length == 0) return default!;

using MemoryStream memStream = new(data);
BinaryDecoder decoder = new(memStream);
Expand Down Expand Up @@ -329,6 +330,7 @@ public override TData Deserialize(string topic, byte[] data)
public override TData DeserializeWithHeaders(string topic, Headers headers, byte[] data)
{
if (_defaultSerDes != null) return _defaultSerDes.DeserializeWithHeaders(topic, headers, data);
if (data == null || data.Length == 0) return default!;

using MemoryStream memStream = new(data);
JsonDecoder decoder = new(AvroKeyContainer._SCHEMA, memStream);
Expand Down Expand Up @@ -508,6 +510,8 @@ public override TData Deserialize(string topic, byte[] data)
/// <inheritdoc cref="SerDes{TData, TJVM}.DeserializeWithHeaders(string, Headers, TJVM)"/>
public override TData DeserializeWithHeaders(string topic, Headers headers, byte[] data)
{
if (data == null || data.Length == 0) return default!;

using MemoryStream memStream = new(data);
BinaryDecoder decoder = new(memStream);
TData t = (TData)Activator.CreateInstance(typeof(TData))!;
Expand Down Expand Up @@ -681,6 +685,8 @@ public override TData Deserialize(string topic, byte[] data)
/// <inheritdoc cref="SerDes{TData, TJVM}.DeserializeWithHeaders(string, Headers, TJVM)"/>
public override TData DeserializeWithHeaders(string topic, Headers headers, byte[] data)
{
if (data == null || data.Length == 0) return default!;

using MemoryStream memStream = new(data);
JsonDecoder decoder = new(AvroValueContainer._SCHEMA, memStream);
TData t = (TData)Activator.CreateInstance(typeof(TData))!;
Expand Down
4 changes: 2 additions & 2 deletions src/net/KEFCore.SerDes.Protobuf/ProtobufKEFCoreSerDes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public override TData DeserializeWithHeaders(string topic, Headers headers, byte
{
if (_defaultSerDes != null) return _defaultSerDes.DeserializeWithHeaders(topic, headers, data);

if (data == null) return default!;
if (data == null || data.Length == 0) return default!;

KeyContainer container = KeyContainer.Parser.ParseFrom(data);

Expand Down Expand Up @@ -315,7 +315,7 @@ public override TData Deserialize(string topic, byte[] data)
/// <inheritdoc cref="SerDes{TData, TJVM}.DeserializeWithHeaders(string, Headers, TJVM)"/>
public override TData DeserializeWithHeaders(string topic, Headers headers, byte[] data)
{
if (data == null) return default!;
if (data == null || data.Length == 0) return default!;
var container = Storage.ValueContainer.Parser.ParseFrom(data);
return (Activator.CreateInstance(typeof(TData), container) as TData)!;
}
Expand Down
4 changes: 2 additions & 2 deletions src/net/KEFCore.SerDes/DefaultKEFCoreSerDes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public override TData DeserializeWithHeaders(string topic, Headers headers, byte
{
if (_defaultSerDes != null) return _defaultSerDes.DeserializeWithHeaders(topic, headers, data);

if (data == null) return default!;
if (data == null || data.Length == 0) return default!;
return System.Text.Json.JsonSerializer.Deserialize<TData>(data, _options)!;
}
}
Expand Down Expand Up @@ -315,7 +315,7 @@ public override TData Deserialize(string topic, byte[] data)
/// <inheritdoc cref="SerDes{TData, TJVM}.DeserializeWithHeaders(string, Headers, TJVM)"/>
public override TData DeserializeWithHeaders(string topic, Headers headers, byte[] data)
{
if (data == null) return default!;
if (data == null || data.Length == 0) return default!;
return System.Text.Json.JsonSerializer.Deserialize<TData>(data, _options)!;
}
}
Expand Down
Loading