Skip to content

Undefined array key #859

@medarob

Description

@medarob

Because of some wrong formated HTML (<ul> list element without <ul>, only <li>) we get the following warnings/errors: (TCPDF 6.11.2)

Core: Error handler (FE): PHP Warning: Undefined array key 0 in /var/www/typo3/vendor/tecnickcom/tcpdf/tcpdf.php line 20833
Core: Error handler (FE): PHP Warning: Undefined array key -1 in /var/www/typo3/vendor/tecnickcom/tcpdf/tcpdf.php line 20689
Core: Error handler (FE): PHP Warning: Undefined array key 0 in /var/www/typo3/vendor/tecnickcom/tcpdf/tcpdf.php line 19318

This patch seems to solve the issue.

--- a/tcpdf.php	2026-03-24 10:04:42.874321210 +0000
+++ b/tcpdf.php	2026-03-24 10:04:44.611931363 +0000
@@ -19315,7 +19315,7 @@
 				if ($key > 2) {
 					$this->addHTMLVertSpace($hbz, $hb, $cell, $firsttag);
 				}
-				if ($this->listordered[$this->listnum]) {
+				if (!empty($this->listordered[$this->listnum])) {
 					// ordered item
 					if (isset($parent['attribute']['type']) AND !TCPDF_STATIC::empty_string($parent['attribute']['type'])) {
 						$this->lispacer = $parent['attribute']['type'];
@@ -19326,6 +19326,9 @@
 					} else {
 						$this->lispacer = '#';
 					}
+					if (!isset($this->listcount[$this->listnum])) {
+						$this->listcount[$this->listnum] = 0;
+					}
 					++$this->listcount[$this->listnum];
 					if (isset($tag['attribute']['value'])) {
 						$this->listcount[$this->listnum] = intval($tag['attribute']['value']);
@@ -20686,7 +20689,7 @@
 		} elseif ($listtype == '!') {
 			// set default list type for unordered list
 			$deftypes = array('disc', 'circle', 'square');
-			$listtype = $deftypes[($listdepth - 1) % 3];
+			$listtype = $deftypes[max(0, ($listdepth - 1) % 3)];
 		} elseif ($listtype == '#') {
 			// set default list type for ordered list
 			$listtype = 'decimal';
@@ -20769,7 +20772,7 @@
 			// $textitem
 			case '1':
 			case 'decimal': {
-				$textitem = $this->listcount[$this->listnum];
+				$textitem = $this->listcount[$this->listnum] ?? '';
 				break;
 			}
 			case 'decimal-leading-zero': {
@@ -20830,7 +20833,7 @@
 			}
 			*/
 			default: {
-				$textitem = $this->listcount[$this->listnum];
+				$textitem = $this->listcount[$this->listnum] ?? '';
 			}
 		}
 		if (!TCPDF_STATIC::empty_string($textitem)) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions