diff --git a/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java b/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java
index 56b6289ee1..6e4d39e1b3 100644
--- a/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java
+++ b/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java
@@ -464,7 +464,7 @@ Element getFromStack(String elName) {
final int upper = bottom >= maxQueueDepth ? bottom - maxQueueDepth : 0;
for (int pos = bottom; pos >= upper; pos--) {
Element next = stack.get(pos);
- if (next.elementIs(elName, next.tag().namespace())) {
+ if (next.elementIs(elName, NamespaceHtml)) {
return next;
}
}
@@ -488,7 +488,7 @@ boolean removeFromStack(Element el) {
Element popStackToClose(String elName) {
for (int pos = stack.size() -1; pos >= 0; pos--) {
Element el = pop();
- if (el.elementIs(elName, el.tag().namespace())) {
+ if (el.elementIs(elName, NamespaceHtml)) {
return el;
}
}
diff --git a/src/test/resources/fuzztests/65147.html.gz b/src/test/resources/fuzztests/65147.html.gz
new file mode 100644
index 0000000000..4e1edd0e8b
Binary files /dev/null and b/src/test/resources/fuzztests/65147.html.gz differ