Fix embedded spaces in tar stream EVEN HARDER
Change-Id: I97ac586ff3541a05d73e1e53f680517c15e6c662
diff --git a/libs/utils/BackupHelpers.cpp b/libs/utils/BackupHelpers.cpp
index b433fd3..f933199f 100644
--- a/libs/utils/BackupHelpers.cpp
+++ b/libs/utils/BackupHelpers.cpp
@@ -503,10 +503,10 @@
needExtended = true;
}
- // Non-7bit-clean path or embedded spaces also mean needing pax extended format
+ // Non-7bit-clean path also means needing pax extended format
if (!needExtended) {
for (size_t i = 0; i < filepath.length(); i++) {
- if ((filepath[i] & 0x80) != 0 || filepath[i] == ' ') {
+ if ((filepath[i] & 0x80) != 0) {
needExtended = true;
break;
}
diff --git a/services/java/com/android/server/BackupManagerService.java b/services/java/com/android/server/BackupManagerService.java
index b568af1..c28732e 100644
--- a/services/java/com/android/server/BackupManagerService.java
+++ b/services/java/com/android/server/BackupManagerService.java
@@ -2859,6 +2859,7 @@
final int end = offset + maxChars;
for (int i = offset; i < end; i++) {
final byte b = data[i];
+ // Numeric fields in tar can terminate with either NUL or SPC
if (b == 0 || b == ' ') break;
if (b < '0' || b > ('0' + radix - 1)) {
throw new IOException("Invalid number in header");
@@ -2871,8 +2872,8 @@
String extractString(byte[] data, int offset, int maxChars) throws IOException {
final int end = offset + maxChars;
int eos = offset;
- // tar string fields can end with either NUL or SPC
- while (eos < end && data[eos] != 0 && data[eos] != ' ') eos++;
+ // tar string fields terminate early with a NUL
+ while (eos < end && data[eos] != 0) eos++;
return new String(data, offset, eos-offset, "US-ASCII");
}