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

Java: Fix byte GlideString conversion to String bug #2271

Merged

Conversation

GumpacG
Copy link
Collaborator

@GumpacG GumpacG commented Sep 11, 2024

Description

Fixes a bug that incorrectly converts non UTF-8 bytes GlideString to String with the value "Value not convertible to string: byte[] " instead of throwing an exception.

Affected APIs:

convertMapToKeyValueGlideStringArray:

  • public CompletableFuture<String> msetBinary(@NonNull Map<GlideString, GlideString> keyValueMap)
  • public CompletableFuture<Long> hset( @NonNull GlideString key, @NonNull Map<GlideString, GlideString> fieldValueMap)
  • public CompletableFuture<GlideString> xadd( @NonNull GlideString key, @NonNull Map<GlideString, GlideString> values, @NonNull StreamAddOptionsBinary options)
  • public CompletableFuture<Boolean> msetnxBinary( @NonNull Map<GlideString, GlideString> keyValueMap)

convertNestedArrayToKeyValueGlideStringArray:

  • public CompletableFuture<GlideString> xadd( @NonNull GlideString key, @NonNull GlideString[][] values, @NonNull StreamAddOptionsBinary options)

convertMapToValueKeyStringArrayBinary:

  • public CompletableFuture<Long> zadd( @NonNull GlideString key, @NonNull Map<GlideString, Double> membersScoresMap, @NonNull ZAddOptions options, boolean changed)

Reproduction steps for the bug:

Run

        byte[] nonUTF8Bytes = new byte[] {(byte) 0xEE};
        GlideString hashKey = gs(UUID.randomUUID().toString());
        GlideString value = gs(nonUTF8Bytes);
        String stringField = "field";
        Map<GlideString, GlideString> fieldValueMap = Map.of(gs(stringField), value);

        assertEquals(1, client.hset(hashKey, fieldValueMap).get());
        System.out.println(client.hget(hashKey.toString(), stringField).get());

See the output to be Value not convertible to string: byte[] 13

Expected

We expect an exception to be thrown in order to avoid unintended data to be stored in the server.

@GumpacG GumpacG added the java issues and fixes related to the java client label Sep 11, 2024
@GumpacG GumpacG requested a review from a team as a code owner September 11, 2024 01:00
@GumpacG GumpacG force-pushed the java/integ_glidestring_tests_valkey-110 branch from 3612356 to 4536917 Compare September 11, 2024 15:31
CHANGELOG.md Outdated Show resolved Hide resolved
@GumpacG GumpacG added the bug Something isn't working label Sep 11, 2024
@GumpacG GumpacG changed the title Java: Add test for GlideString Java: Fix byte conversion to GlideString bug Sep 11, 2024
@GumpacG GumpacG force-pushed the java/integ_glidestring_tests_valkey-110 branch from 4536917 to d8d1ae2 Compare September 11, 2024 20:34
@GumpacG GumpacG changed the title Java: Fix byte conversion to GlideString bug Java: Fix byte GlideString conversion to String bug Sep 11, 2024
Signed-off-by: Guian Gumpac <[email protected]>
Signed-off-by: Guian Gumpac <[email protected]>
Signed-off-by: Guian Gumpac <[email protected]>
Signed-off-by: Guian Gumpac <[email protected]>
Signed-off-by: Guian Gumpac <[email protected]>
@GumpacG GumpacG force-pushed the java/integ_glidestring_tests_valkey-110 branch from 4a14bbc to 8b614fb Compare September 11, 2024 20:38
CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: Andrew Carbonetto <[email protected]>
Signed-off-by: Guian Gumpac <[email protected]>
Copy link
Collaborator

@Yury-Fridlyand Yury-Fridlyand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please list which APIs (commands) you fixed in the PR description

@GumpacG GumpacG merged commit cf5483f into valkey-io:main Sep 11, 2024
13 checks passed
@GumpacG GumpacG deleted the java/integ_glidestring_tests_valkey-110 branch September 11, 2024 23:14
@acarbonetto acarbonetto mentioned this pull request Sep 14, 2024
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working java issues and fixes related to the java client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants