Skip to content

Deeply nested ServerTimestamps cause StackOverflowError #4702

@sk-takahiro-kurebayashi

Description

[REQUIRED] Step 2: Describe your environment

  • Android Studio version: Android Studio Electric Eel | 2022.1.1 Patch 1
  • Firebase Component: Firestore
  • Component version: 24.4.0, 24.4.3

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

  1. Disconnect from the Internet.
  2. Launch my app.
  3. Write a Document containing a field having @ServerTimestamp annotation by “Set” operation with “merge” option.
  4. Repeat step 3 many times (some hundreds).
  5. SQLiteDocumentOverlayCache#saveOverlay or decodeOverlay throws StackOverflowError while serializing/deserializing nested "ServerTimestamp" (MapValue) objects.

Relevant Code:

IMHO, no need to keep nested previous value of "ServerTimestamp" object. And, just the oldest value is needed.
So, below patch resolves "deeply nested ServerTimestamp". But, saved overlay causes StackOverflow when it is parsed.

diff --git a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/ServerTimestamps.java b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/ServerTimestamps.java
index 7ae19eadc..ef7b547fd 100644
--- a/firebase-firestore/src/main/java/com/google/firebase/firestore/model/ServerTimestamps.java
+++ b/firebase-firestore/src/main/java/com/google/firebase/firestore/model/ServerTimestamps.java
@@ -62,8 +62,9 @@ public final class ServerTimestamps {
             .putFields(TYPE_KEY, encodedType)
             .putFields(LOCAL_WRITE_TIME_KEY, encodeWriteTime);
 
-    if (previousValue != null) {
-      mapRepresentation.putFields(PREVIOUS_VALUE_KEY, previousValue);
+    Value actualPreviousValue = previousValue == null ? null : getPreviousValue(previousValue);
+    if (actualPreviousValue != null) {
+      mapRepresentation.putFields(PREVIOUS_VALUE_KEY, actualPreviousValue);
     }
 
     return Value.newBuilder().setMapValue(mapRepresentation).build();

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions