malformed styles

if styles are malformed html, then recreation fails with OutOfBounds,
end tag if error occurs to prevent crash
This commit is contained in:
Connor Tumbleson 2014-02-09 20:45:16 -06:00
parent f980cfad97
commit d90bea10ce
3 changed files with 22 additions and 7 deletions

View File

@ -33,6 +33,7 @@ v2.0.0 (TBA)
-Fixed (issue #601) - Make StringBlock thread safe (Thanks aluedeke)
-Fixed (issue #238) - Fixed truncated UTF-16 strings
-Fixed (issue #584) - Fixed horrible spacing, aligned for 4 spaces.
-Fixed (issue #196) - Fixed style crash due to malformed styles.
-Added output to list Apktool version to help debugging.
-Updated known bytes for configurations to 38 (from addition of layout direction)
-Fixed NPE when handling odex apks even with --no-src specified. (Thanks Rodrigo Chiossi)

View File

@ -184,18 +184,27 @@ public class StringBlock {
boolean loop = true;
while (loop) {
int pos2 = tag.indexOf('=', pos + 1);
builder.append(' ').append(tag.substring(pos + 1, pos2)).append("=\"");
pos = tag.indexOf(';', pos2 + 1);
String val;
if (pos != -1) {
val = tag.substring(pos2 + 1, pos);
// malformed style information will cause crash. so
// prematurely end style tags, if recreation
// cannot be created.
if (pos2 != -1) {
builder.append(' ').append(tag.substring(pos + 1, pos2)).append("=\"");
pos = tag.indexOf(';', pos2 + 1);
String val;
if (pos != -1) {
val = tag.substring(pos2 + 1, pos);
} else {
loop = false;
val = tag.substring(pos2 + 1);
}
builder.append(ResXmlEncoders.escapeXmlChars(val)).append('"');
} else {
loop = false;
val = tag.substring(pos2 + 1);
}
builder.append(ResXmlEncoders.escapeXmlChars(val)).append('"');
}
}
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="test_formatting1"><a href="http://www.foo.com" style="text-decoration:none;">http://www.foo.com</a></string>
<string name="test_formatting2"><a href="http://www.foo.com" style="text-decoration:none">http://www.foo.com</a></string>
</resources>