Skip to content

Commit d1443d1

Browse files
authored
winlogbeat: fix XML rendering on Windows arm64 (#51055)
Treat Windows arm64 as a 64-bit pointer architecture when decoding rendered Event Log values so XML rendering no longer reports unsupported architecture errors. Assisted-By: Cursor
1 parent 9f4ebac commit d1443d1

3 files changed

Lines changed: 68 additions & 1 deletion

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# REQUIRED
2+
# Kind can be one of:
3+
# - breaking-change: a change to previously-documented behavior
4+
# - deprecation: functionality that is being removed in a later release
5+
# - bug-fix: fixes a problem in a previous version
6+
# - enhancement: extends functionality but does not break or fix existing behavior
7+
# - feature: new functionality
8+
# - known-issue: problems that we are aware of in a given version
9+
# - security: impacts on the security of a product or a user’s deployment.
10+
# - upgrade: important information for someone upgrading from a prior version
11+
# - other: does not fit into any of the other categories
12+
kind: bug-fix
13+
14+
# REQUIRED for all kinds
15+
# Change summary; a 80ish characters long description of the change.
16+
summary: Fix winlog XML rendering on Windows arm64
17+
18+
# REQUIRED for breaking-change, deprecation, known-issue
19+
# Long description; in case the summary is not enough to describe the change
20+
# this field accommodate a description without length limits.
21+
# description:
22+
23+
# REQUIRED for breaking-change, deprecation, known-issue
24+
# impact:
25+
26+
# REQUIRED for breaking-change, deprecation, known-issue
27+
# action:
28+
29+
# REQUIRED for all kinds
30+
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
31+
component: winlogbeat
32+
33+
# AUTOMATED
34+
# OPTIONAL to manually add other PR URLs
35+
# PR URL: A link the PR that added the changeset.
36+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
37+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
38+
# Please provide it if you are adding a fragment for a different PR.
39+
# pr: https://github.com/owner/repo/1234
40+
41+
# AUTOMATED
42+
# OPTIONAL to manually add other issue URLs
43+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
44+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
45+
# issue: https://github.com/owner/repo/1234

winlogbeat/sys/wineventlog/wineventlog_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ func offset(buffer []byte, reader io.Reader) (uint64, error) {
469469
switch runtime.GOARCH {
470470
default:
471471
return 0, fmt.Errorf("unhandled architecture: %s", runtime.GOARCH)
472-
case "amd64":
472+
case "amd64", "arm64":
473473
err = binary.Read(reader, binary.LittleEndian, &dataPtr)
474474
if err != nil {
475475
return 0, err

winlogbeat/sys/wineventlog/wineventlog_windows_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,22 @@ package wineventlog
1919

2020
import (
2121
"bytes"
22+
"encoding/binary"
2223
"encoding/xml"
2324
"flag"
2425
"fmt"
2526
"io"
2627
"os"
2728
"path/filepath"
2829
"reflect"
30+
"runtime"
2931
"strings"
3032
"testing"
33+
"unsafe"
3134

3235
"github.com/google/go-cmp/cmp"
3336
"github.com/stretchr/testify/assert"
37+
"github.com/stretchr/testify/require"
3438

3539
"github.com/elastic/beats/v7/winlogbeat/sys/winevent"
3640
)
@@ -147,6 +151,24 @@ func TestWinEventLog(t *testing.T) {
147151
}
148152
}
149153

154+
func TestOffsetSupportsWindowsPointerArchitectures(t *testing.T) {
155+
buffer := make([]byte, 16)
156+
ptr := uintptr(unsafe.Pointer(&buffer[8]))
157+
reader := &bytes.Buffer{}
158+
switch runtime.GOARCH {
159+
case "amd64", "arm64":
160+
require.NoError(t, binary.Write(reader, binary.LittleEndian, uint64(ptr)), "write 64-bit pointer")
161+
case "386":
162+
require.NoError(t, binary.Write(reader, binary.LittleEndian, uint32(ptr)), "write 32-bit pointer")
163+
default:
164+
t.Skipf("unsupported Windows test architecture %q", runtime.GOARCH)
165+
}
166+
167+
got, err := offset(buffer, reader)
168+
require.NoError(t, err, "offset should support %s pointer layout", runtime.GOARCH)
169+
assert.Equal(t, uint64(8), got, "offset should point inside the render buffer")
170+
}
171+
150172
// unmarshalXMLEvents unmarshals a complete set of events from the XML data
151173
// in the provided io.Reader. GUID values are canonicalised to lowercase.
152174
func unmarshalXMLEvents(r io.Reader) ([]winevent.Event, error) {

0 commit comments

Comments
 (0)