Skip to content

Commit f1e3170

Browse files
David Christiegitbuildkicker
authored andcommitted
DO NOT MERGE: Fix vulnerability where large GPS XTRA data can be
injected. -Can potentially crash system with OOM. Bug: 29555864 Change-Id: I7157f48dddf148a9bcab029cf12e26a58d8054f4 (cherry picked from commit 5439aabb165b5a760d1e580016bf1d6fd963cb65)
1 parent ca692c2 commit f1e3170

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

services/core/java/com/android/server/location/GpsXtraDownloader.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121

2222
import java.net.HttpURLConnection;
2323
import java.net.URL;
24-
import libcore.io.Streams;
2524

25+
import libcore.io.IoUtils;
26+
27+
import java.io.ByteArrayOutputStream;
28+
import java.io.InputStream;
2629
import java.io.IOException;
2730
import java.util.Properties;
2831
import java.util.Random;
@@ -36,6 +39,7 @@ public class GpsXtraDownloader {
3639

3740
private static final String TAG = "GpsXtraDownloader";
3841
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
42+
private static final long MAXIMUM_CONTENT_LENGTH_BYTES = 1000000; // 1MB.
3943
private static final String DEFAULT_USER_AGENT = "Android";
4044

4145
private final String[] mXtraServers;
@@ -121,7 +125,19 @@ protected byte[] doDownload(String url) {
121125
return null;
122126
}
123127

124-
return Streams.readFully(connection.getInputStream());
128+
try (InputStream in = connection.getInputStream()) {
129+
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
130+
byte[] buffer = new byte[1024];
131+
int count;
132+
while ((count = in.read(buffer)) != -1) {
133+
bytes.write(buffer, 0, count);
134+
if (bytes.size() > MAXIMUM_CONTENT_LENGTH_BYTES) {
135+
if (DEBUG) Log.d(TAG, "XTRA file too large");
136+
return null;
137+
}
138+
}
139+
return bytes.toByteArray();
140+
}
125141
} catch (IOException ioe) {
126142
if (DEBUG) Log.d(TAG, "Error downloading gps XTRA: ", ioe);
127143
} finally {
@@ -133,3 +149,4 @@ protected byte[] doDownload(String url) {
133149
}
134150

135151
}
152+

0 commit comments

Comments
 (0)