Skip to content

Commit eacf3ec

Browse files
authored
Merge pull request #77 from TheManticoreProject/bugfix-acl-header-marshal-rawbytessize
[bug] Fix RawBytesSize accumulating across Marshal calls in ACL headers (#74)
2 parents 14b2071 + 819efb8 commit eacf3ec

4 files changed

Lines changed: 50 additions & 0 deletions

acl/DiscretionaryAccessControlListHeader.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ func (daclheader *DiscretionaryAccessControlListHeader) Unmarshal(marshalledData
6666
func (daclheader *DiscretionaryAccessControlListHeader) Marshal() ([]byte, error) {
6767
var marshalledData []byte
6868

69+
daclheader.RawBytesSize = 0
70+
6971
bytesStream, err := daclheader.Revision.Marshal()
7072
if err != nil {
7173
return nil, err

acl/DiscretionaryAccessControlListHeader_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,27 @@ func TestDiscretionaryAccessControlListHeader_Involution(t *testing.T) {
7575
t.Errorf("Sbz2 value not preserved: expected %d, got %d", daclHeader.Sbz2, daclHeader2.Sbz2)
7676
}
7777
}
78+
79+
// TestDiscretionaryAccessControlListHeader_Marshal_RawBytesSize_Idempotent
80+
// verifies that repeated Marshal calls report the fixed 8-byte header size
81+
// rather than accumulating it.
82+
func TestDiscretionaryAccessControlListHeader_Marshal_RawBytesSize_Idempotent(t *testing.T) {
83+
daclHeaderBytes, err := hex.DecodeString("0100140002000000")
84+
if err != nil {
85+
t.Fatalf("Failed to decode header hex: %v", err)
86+
}
87+
88+
daclHeader := &DiscretionaryAccessControlListHeader{}
89+
if _, err := daclHeader.Unmarshal(daclHeaderBytes); err != nil {
90+
t.Fatalf("Failed to unmarshal DACL header: %v", err)
91+
}
92+
93+
for i := 0; i < 3; i++ {
94+
if _, err := daclHeader.Marshal(); err != nil {
95+
t.Fatalf("Marshal() call %d error = %v", i, err)
96+
}
97+
if daclHeader.RawBytesSize != 8 {
98+
t.Errorf("after Marshal() call %d: RawBytesSize = %d, want 8", i, daclHeader.RawBytesSize)
99+
}
100+
}
101+
}

acl/SystemAccessControlListHeader.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ func (saclheader *SystemAccessControlListHeader) Unmarshal(marshalledData []byte
6565
func (saclheader *SystemAccessControlListHeader) Marshal() ([]byte, error) {
6666
var marshalledData []byte
6767

68+
saclheader.RawBytesSize = 0
69+
6870
bytesStream, err := saclheader.Revision.Marshal()
6971
if err != nil {
7072
return nil, fmt.Errorf("failed to marshal Revision: %w", err)

acl/SystemAccessControlListHeader_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,28 @@ func TestSystemAccessControlListHeader_MarshalUnmarshal(t *testing.T) {
6363
}
6464
}
6565

66+
// TestSystemAccessControlListHeader_Marshal_RawBytesSize_Idempotent verifies
67+
// that repeated Marshal calls report the fixed 8-byte header size rather than
68+
// accumulating it.
69+
func TestSystemAccessControlListHeader_Marshal_RawBytesSize_Idempotent(t *testing.T) {
70+
header := SystemAccessControlListHeader{
71+
Revision: revision.AccessControlListRevision{Value: 0x02},
72+
Sbz1: 0x00,
73+
AclSize: 0x30,
74+
AceCount: 0x05,
75+
Sbz2: 0x00,
76+
}
77+
78+
for i := 0; i < 3; i++ {
79+
if _, err := header.Marshal(); err != nil {
80+
t.Fatalf("Marshal() call %d error = %v", i, err)
81+
}
82+
if header.RawBytesSize != 8 {
83+
t.Errorf("after Marshal() call %d: RawBytesSize = %d, want 8", i, header.RawBytesSize)
84+
}
85+
}
86+
}
87+
6688
func TestSystemAccessControlListHeader_MarshalUnmarshalWithEdgeCases(t *testing.T) {
6789
testCases := []struct {
6890
name string

0 commit comments

Comments
 (0)