Skip to content

Serialize and deserialize between the old and new versions of Fory are incompatible. #2923

@lidothui

Description

@lidothui

Search before asking

  • I had searched in the issues and found no similar issues.

Version

Fory 0.13.1

Component(s)

Java

Minimal reproduce step

I used 0.12.2 fory to serialize an UUID object, belows are the code snippets:

final Fory fory = Fory.builder()
        .withLanguage(Language.JAVA)
        .requireClassRegistration(false)
        .build();

final UUID uuid = UUID.fromString("45985b2a-87ba-4747-b5d6-21ab[45666596](tel:45666596)");
final byte[] bytes = fory.serialize(uuid);


final String filePath = "~/data.fory.uuid.0.12.2";
try (FileOutputStream fos = new FileOutputStream(filePath)) {
    fos.write(bytes);
}

Then I used 0.13.1 fory to deserialize, belows are the code snippets:

final Fory fory = Fory.builder()
        .withLanguage(Language.JAVA)
        .requireClassRegistration(false)
        .build();
final String filePath = "~/data.fory.uuid.0.12.2";
final byte[] readBytes = Files.readAllBytes(Path.of(filePath));

final UUID restored = fory.deserialize(readBytes, UUID.class);

The deserializing codes report the exception:

Exception in thread "main" org.apache.fory.exception.DeserializationException: Failed to deserialize input
        at org.apache.fory.util.ExceptionUtils.handleReadFailed(ExceptionUtils.java:66)
        at org.apache.fory.Fory.deserialize(Fory.java:892)
        at org.apache.fory.Fory.deserialize(Fory.java:805)
        at com.ruijie.rcos.dex.explorer.serializer.ForyFileExample.deserialize(ForyFileExample.java:80)
        at com.ruijie.rcos.dex.explorer.serializer.ForyFileExample.main(ForyFileExample.java:28)
Caused by: java.lang.IndexOutOfBoundsException: readerIndex(5) + length(2) exceeds size(20): org.apache.fory.memory.MemoryBuffer$BoundChecker@1750fbeb
        at org.apache.fory.memory.MemoryBuffer$BoundChecker.fillBuffer(MemoryBuffer.java:189)
        at org.apache.fory.memory.MemoryBuffer.checkReadableBytes(MemoryBuffer.java:2433)
        at org.apache.fory.serializer.StringSerializer.readBytesUnCompressedUTF16(StringSerializer.java:495)
        at org.apache.fory.serializer.StringSerializer.readBytesString(StringSerializer.java:199)
        at org.apache.fory.serializer.StringSerializer.readJavaString(StringSerializer.java:349)
        at org.apache.fory.Fory.readJavaString(Fory.java:774)
        at org.apache.fory.serializer.Serializers$RegexSerializer.read(Serializers.java:528)
        at org.apache.fory.serializer.Serializers$RegexSerializer.read(Serializers.java:515)
        at org.apache.fory.Fory.readDataInternal(Fory.java:1049)
        at org.apache.fory.Fory.readRef(Fory.java:934)
        at org.apache.fory.Fory.deserialize(Fory.java:888)
        ... 3 more

I used 0.12.2 Fory and 0.13.1 Fory to serialize the same UUID string, there is one difference (ac vs ae) in the hexdump files.

Image

What did you expect to see?

Serialize and deserialize between the old and new versions of Fory Should be compatible.

What did you see instead?

Serialize and deserialize between the old and new versions of Fory are incompatible.

Anything Else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions