Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
platform_frameworks_base
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dhina17
platform_frameworks_base
Commits
b817c5e2
Commit
b817c5e2
authored
1 year ago
by
TYM Tsai
Committed by
Android (Google) Code Review
1 year ago
Browse files
Options
Downloads
Plain Diff
Merge "RESTRICT AUTOMERGE: Drop invalid data." into tm-dev
parents
e69d9c81
3c5aa21b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/java/android/os/PersistableBundle.java
+34
-8
34 additions, 8 deletions
core/java/android/os/PersistableBundle.java
with
34 additions
and
8 deletions
core/java/android/os/PersistableBundle.java
+
34
−
8
View file @
b817c5e2
...
...
@@ -21,6 +21,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import
android.annotation.NonNull
;
import
android.annotation.Nullable
;
import
android.util.ArrayMap
;
import
android.util.Slog
;
import
android.util.TypedXmlPullParser
;
import
android.util.TypedXmlSerializer
;
import
android.util.Xml
;
...
...
@@ -50,6 +51,8 @@ import java.util.ArrayList;
*/
public
final
class
PersistableBundle
extends
BaseBundle
implements
Cloneable
,
Parcelable
,
XmlUtils
.
WriteMapCallback
{
private
static
final
String
TAG
=
"PersistableBundle"
;
private
static
final
String
TAG_PERSISTABLEMAP
=
"pbundle_as_map"
;
/** An unmodifiable {@code PersistableBundle} that is always {@link #isEmpty() empty}. */
...
...
@@ -118,7 +121,11 @@ public final class PersistableBundle extends BaseBundle implements Cloneable, Pa
* @hide
*/
public
PersistableBundle
(
Bundle
b
)
{
this
(
b
.
getItemwiseMap
());
this
(
b
,
true
);
}
private
PersistableBundle
(
Bundle
b
,
boolean
throwException
)
{
this
(
b
.
getItemwiseMap
(),
throwException
);
}
/**
...
...
@@ -127,7 +134,7 @@ public final class PersistableBundle extends BaseBundle implements Cloneable, Pa
* @param map a Map containing only those items that can be persisted.
* @throws IllegalArgumentException if any element of #map cannot be persisted.
*/
private
PersistableBundle
(
ArrayMap
<
String
,
Object
>
map
)
{
private
PersistableBundle
(
ArrayMap
<
String
,
Object
>
map
,
boolean
throwException
)
{
super
();
mFlags
=
FLAG_DEFUSABLE
;
...
...
@@ -136,16 +143,23 @@ public final class PersistableBundle extends BaseBundle implements Cloneable, Pa
// Now verify each item throwing an exception if there is a violation.
final
int
N
=
mMap
.
size
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
for
(
int
i
=
N
-
1
;
i
>=
0
;
--
i
)
{
Object
value
=
mMap
.
valueAt
(
i
);
if
(
value
instanceof
ArrayMap
)
{
// Fix up any Maps by replacing them with PersistableBundles.
mMap
.
setValueAt
(
i
,
new
PersistableBundle
((
ArrayMap
<
String
,
Object
>)
value
));
mMap
.
setValueAt
(
i
,
new
PersistableBundle
((
ArrayMap
<
String
,
Object
>)
value
,
throwException
));
}
else
if
(
value
instanceof
Bundle
)
{
mMap
.
setValueAt
(
i
,
new
PersistableBundle
((
(
Bundle
)
value
)
));
mMap
.
setValueAt
(
i
,
new
PersistableBundle
((
Bundle
)
value
,
throwException
));
}
else
if
(!
isValidType
(
value
))
{
throw
new
IllegalArgumentException
(
"Bad value in PersistableBundle key="
+
mMap
.
keyAt
(
i
)
+
" value="
+
value
);
final
String
errorMsg
=
"Bad value in PersistableBundle key="
+
mMap
.
keyAt
(
i
)
+
" value="
+
value
;
if
(
throwException
)
{
throw
new
IllegalArgumentException
(
errorMsg
);
}
else
{
Slog
.
wtfStack
(
TAG
,
errorMsg
);
mMap
.
removeAt
(
i
);
}
}
}
}
...
...
@@ -268,6 +282,15 @@ public final class PersistableBundle extends BaseBundle implements Cloneable, Pa
/** @hide */
public
void
saveToXml
(
TypedXmlSerializer
out
)
throws
IOException
,
XmlPullParserException
{
unparcel
();
// Explicitly drop invalid types an attacker may have added before persisting.
for
(
int
i
=
mMap
.
size
()
-
1
;
i
>=
0
;
--
i
)
{
final
Object
value
=
mMap
.
valueAt
(
i
);
if
(!
isValidType
(
value
))
{
Slog
.
e
(
TAG
,
"Dropping bad data before persisting: "
+
mMap
.
keyAt
(
i
)
+
"="
+
value
);
mMap
.
removeAt
(
i
);
}
}
XmlUtils
.
writeMapXml
(
mMap
,
out
,
this
);
}
...
...
@@ -322,9 +345,12 @@ public final class PersistableBundle extends BaseBundle implements Cloneable, Pa
while
(((
event
=
in
.
next
())
!=
XmlPullParser
.
END_DOCUMENT
)
&&
(
event
!=
XmlPullParser
.
END_TAG
||
in
.
getDepth
()
<
outerDepth
))
{
if
(
event
==
XmlPullParser
.
START_TAG
)
{
// Don't throw an exception when restoring from XML since an attacker could try to
// input invalid data in the persisted file.
return
new
PersistableBundle
((
ArrayMap
<
String
,
Object
>)
XmlUtils
.
readThisArrayMapXml
(
in
,
startTag
,
tagName
,
new
MyReadMapCallback
()));
new
MyReadMapCallback
()),
/* throwException */
false
);
}
}
return
new
PersistableBundle
();
// An empty mutable PersistableBundle
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment