Skip to content

Commit 9e1952b

Browse files
xaionaro@dx.centerxaionaro@dx.center
authored andcommitted
fix: WriteNullStrongBinder format and objects array registration
Two fixes for null binder objects: 1. Write BINDER_TYPE_BINDER type field even for null binders, matching Android's flattenBinder(nullptr) which sets type=BINDER_TYPE_BINDER with binder=0 and cookie=0. Previously wrote all zeros (type=0). 2. Do not record null binder objects in the parcel's objects array. Android's Parcel::writeObject skips the objects array when binder==0 && !nullMetaData, because the kernel should not process null binder objects.
1 parent 8ef949a commit 9e1952b

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

parcel/binder_object.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,17 @@ func (p *Parcel) ReadStrongBinder() (uint32, error) {
133133
return handle, nil
134134
}
135135

136-
// WriteNullStrongBinder writes a null flat_binder_object (all zeros)
137-
// followed by the UNDECLARED stability level.
136+
// WriteNullStrongBinder writes a null flat_binder_object.
137+
// Android's flattenBinder(nullptr) writes type=BINDER_TYPE_BINDER with
138+
// binder=0 and cookie=0. The null object is NOT recorded in the objects
139+
// array (Parcel::writeObject skips it when binder==0 && !nullMetaData).
140+
// Followed by UNDECLARED stability level (finishFlattenBinder).
138141
func (p *Parcel) WriteNullStrongBinder() {
139-
offset := uint64(p.Len())
140-
p.objects = append(p.objects, offset)
141-
p.grow(flatBinderObjectSize)
142+
buf := p.grow(flatBinderObjectSize)
143+
144+
// type must be BINDER_TYPE_BINDER even for null (Android convention).
145+
binary.LittleEndian.PutUint32(buf[0:], binderTypeBinder)
146+
// flags, binder, cookie are all zero (from grow's zero-fill).
142147

143148
// Null binder uses UNDECLARED stability.
144149
p.WriteInt32(StabilityUndeclared)

0 commit comments

Comments
 (0)