Skip to content

Commit f89ece5

Browse files
cpovirkcgdecker
authored andcommitted
Avoid presizing arrays.
RELNOTES=Fixed Denial of Service vulnerability for servers that use Guava and deserialize attacker data: [CVE-2018-10237](https://github.com/google/guava/wiki/CVE-2018-10237). ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=194113840
1 parent 5d8209c commit f89ece5

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

android/guava/src/com/google/common/util/concurrent/AtomicDoubleArray.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import static java.lang.Double.longBitsToDouble;
1818

1919
import com.google.common.annotations.GwtIncompatible;
20+
import com.google.common.primitives.ImmutableLongArray;
2021
import com.google.errorprone.annotations.CanIgnoreReturnValue;
2122
import java.util.concurrent.atomic.AtomicLongArray;
2223

@@ -247,13 +248,11 @@ private void readObject(java.io.ObjectInputStream s)
247248
throws java.io.IOException, ClassNotFoundException {
248249
s.defaultReadObject();
249250

250-
// Read in array length and allocate array
251251
int length = s.readInt();
252-
this.longs = new AtomicLongArray(length);
253-
254-
// Read in all elements in the proper order.
252+
ImmutableLongArray.Builder builder = ImmutableLongArray.builder();
255253
for (int i = 0; i < length; i++) {
256-
set(i, s.readDouble());
254+
builder.add(doubleToRawLongBits(s.readDouble()));
257255
}
256+
this.longs = new AtomicLongArray(builder.build().toArray());
258257
}
259258
}

guava-gwt/src/com/google/common/collect/CompoundOrdering_CustomFieldSerializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static void deserialize(SerializationStreamReader reader, CompoundOrderin
3636
public static CompoundOrdering<Object> instantiate(SerializationStreamReader reader)
3737
throws SerializationException {
3838
int n = reader.readInt();
39-
List<Comparator<Object>> comparators = new ArrayList<>(n);
39+
List<Comparator<Object>> comparators = new ArrayList<>();
4040
for (int i = 0; i < n; i++) {
4141
comparators.add((Comparator<Object>) reader.readObject());
4242
}

guava/src/com/google/common/util/concurrent/AtomicDoubleArray.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import static java.lang.Double.longBitsToDouble;
1818

1919
import com.google.common.annotations.GwtIncompatible;
20+
import com.google.common.primitives.ImmutableLongArray;
2021
import com.google.errorprone.annotations.CanIgnoreReturnValue;
2122
import java.util.concurrent.atomic.AtomicLongArray;
2223

@@ -247,13 +248,11 @@ private void readObject(java.io.ObjectInputStream s)
247248
throws java.io.IOException, ClassNotFoundException {
248249
s.defaultReadObject();
249250

250-
// Read in array length and allocate array
251251
int length = s.readInt();
252-
this.longs = new AtomicLongArray(length);
253-
254-
// Read in all elements in the proper order.
252+
ImmutableLongArray.Builder builder = ImmutableLongArray.builder();
255253
for (int i = 0; i < length; i++) {
256-
set(i, s.readDouble());
254+
builder.add(doubleToRawLongBits(s.readDouble()));
257255
}
256+
this.longs = new AtomicLongArray(builder.build().toArray());
258257
}
259258
}

0 commit comments

Comments
 (0)