Skip to content

Commit c988b29

Browse files
authored
fix: avoid infinite loops parsing Maven poms with syntax errors (#188)
1 parent 8bc880e commit c988b29

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<project>
2+
<properties>
3+
<${Id}.version>${project.version}</${Id}.version>
4+
</properties>
5+
6+
<dependencies>
7+
<dependency>
8+
<groupId>io.netty</groupId>
9+
<artifactId>netty-all</artifactId>
10+
<version>4.1.42.Final</version>
11+
</dependency>
12+
</dependencies>
13+
</project>

pkg/lockfile/parse-maven-lock.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ func (p *MavenLockProperties) UnmarshalXML(d *xml.Decoder, start xml.StartElemen
7272
p.m = map[string]string{}
7373

7474
for {
75-
t, _ := d.Token()
75+
t, err := d.Token()
76+
77+
if err != nil {
78+
return fmt.Errorf("%w", err)
79+
}
7680

7781
switch tt := t.(type) {
7882
case xml.StartElement:

pkg/lockfile/parse-maven-lock_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ func TestParseMavenLock_Invalid(t *testing.T) {
2323
expectPackages(t, packages, []lockfile.PackageDetails{})
2424
}
2525

26+
func TestParseMavenLock_InvalidSyntax(t *testing.T) {
27+
t.Parallel()
28+
29+
packages, err := lockfile.ParseMavenLock("fixtures/maven/invalid-syntax.xml")
30+
31+
expectErrContaining(t, err, "XML syntax error")
32+
expectPackages(t, packages, []lockfile.PackageDetails{})
33+
}
34+
2635
func TestParseMavenLock_NoPackages(t *testing.T) {
2736
t.Parallel()
2837

0 commit comments

Comments
 (0)