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

Value validation fails on BSON-encoded maps of binaries #95

Closed
Annopaolo opened this issue Sep 15, 2023 · 1 comment
Closed

Value validation fails on BSON-encoded maps of binaries #95

Annopaolo opened this issue Sep 15, 2023 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@Annopaolo
Copy link
Collaborator

Annopaolo commented Sep 15, 2023

When a BSON map containing well-formed binary values, e.g. <<18, 0, 0, 0, 5, 118, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 5, 0>>, is passed to Cyanide 2.0 decode/1 (resulting in %{"v" => %Cyanide.Binary{subtype: :generic, data: <<1, 2, 3, 4, 5>>}} and then to Astarte.Core.Mapping.ValueType.validate_value/1, the function returns {:error, :unexpected_value_type} instead of the correct :ok.
This happens because the function body pattern-matches on the tuple {_subtype, bin} rather than on a %Cyanide.Binary{} struct, see here:

{{_subtype, bin}, :binaryblob} when is_binary(bin) ->
if byte_size(bin) > @blob_size do
{:error, :value_size_exceeded}
else
:ok
end

To fix this, the correct Cyanide.Binary{subtype: _subtype, data: binary} struct should be used.
The change happened when switching to the 2.0.0 version of Cyanide, i.e. starting from the release-1.1 branch.

@Annopaolo Annopaolo added bug Something isn't working good first issue Good for newcomers labels Sep 15, 2023
@Annopaolo
Copy link
Collaborator Author

Closed by #96.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
Status: Done
Development

No branches or pull requests

1 participant