diff --git a/src/display/text_layer.js b/src/display/text_layer.js index bf674bcb3..5d43cdc0c 100644 --- a/src/display/text_layer.js +++ b/src/display/text_layer.js @@ -224,6 +224,8 @@ function render(task) { } class TextLayerRenderTask { + #initialContainer = null; + constructor({ textContent, textContentStream, @@ -235,6 +237,7 @@ class TextLayerRenderTask { this._textContent = textContent; this._textContentStream = textContentStream; this._container = container; + this.#initialContainer = container; this._document = container.ownerDocument; this._viewport = viewport; this._textDivs = textDivs || []; @@ -318,7 +321,13 @@ class TextLayerRenderTask { } parent.append(this._container); } else if (item.type === "endMarkedContent") { - this._container = this._container.parentNode; + const parent = this._container.parentNode; + if (!parent || this._container === this.#initialContainer) { + // Handle unbalanced beginMarkedContent/endMarkedContent operators + // (fixes issue15629.pdf). + continue; + } + this._container = parent; } continue; } diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index dd308124f..087061baa 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -302,6 +302,7 @@ !issue5751.pdf !bug893730.pdf !bug864847.pdf +!issue15629.pdf !issue1002.pdf !issue925.pdf !issue2840.pdf diff --git a/test/pdfs/issue15629.pdf b/test/pdfs/issue15629.pdf new file mode 100644 index 000000000..d7e98a71a Binary files /dev/null and b/test/pdfs/issue15629.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index c782b5efa..081e5994d 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -2263,6 +2263,12 @@ "rounds": 1, "type": "eq" }, + { "id": "issue15629", + "file": "pdfs/issue15629.pdf", + "md5": "689771b7f5c86c783c56aa8dedab0057", + "rounds": 1, + "type": "text" + }, { "id": "glyph_accent", "file": "pdfs/glyph_accent.pdf", "md5": "1526e4edaa3ec439ebf156d0a0b385aa",