Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in 6.7.2 - undefined index error #699

Open
fisharebest opened this issue Mar 20, 2024 · 1 comment
Open

Regression in 6.7.2 - undefined index error #699

fisharebest opened this issue Mar 20, 2024 · 1 comment

Comments

@fisharebest
Copy link
Contributor

fisharebest commented Mar 20, 2024

Upgrading from 6.6.5 to 6.7.2 causes an undefined index error in my test scripts.

ErrorException: Undefined array key -1

/Users/gr4376/Projects/webtrees/vendor/tecnickcom/tcpdf/tcpdf.php:18829
/Users/gr4376/Projects/webtrees/vendor/tecnickcom/tcpdf/tcpdf.php:5934

The offending code is $dom[$key-1].

18829                 if ($ln AND (!($cell AND ($dom[$key-1]['value'] == 'table')))) {
18830                         $this->Ln($this->lasth);
18831                         if (($this->y < $maxbottomliney) AND ($startlinepage == $this->page)) {
18832                                 $this->y = $maxbottomliney;
18833                         }
18834                 }

Using git bisect, I have traced the issue to this commit. Removing this change allows the 6.7.2 code to run without error.

$ git diff 883cbb44093bf9d2ed47a2ada457ff3368eb0661..1ae5c4721cecb6be1fa1c0bebb506ed454a3e02d
diff --git a/tcpdf.php b/tcpdf.php
index 51e3c2f..1df2246 100644
--- a/tcpdf.php
+++ b/tcpdf.php
@@ -16389,6 +16389,9 @@ class TCPDF {
         * @since 3.2.000 (2008-06-20)
         */
        protected function getHtmlDomArray($html) {
+               if(empty($html)) {
+                       return array();
+               }
                // array of CSS styles ( selector => properties).
                $css = array();
                // get CSS array defined at previous call

Debugging shows that when the $html parameter is an empty string, then the returned array would otherwise be non-empty. For example, this:

array (
  0 => 
  array (
    'tag' => false,
    'block' => false,
    'value' => '',
    'parent' => 0,
    'hide' => false,
    'fontname' => 'dejavusans',
    'fontstyle' => '',
    'fontsize' => 8.0,
    'font-stretch' => 100,
    'letter-spacing' => 0,
    'stroke' => 0,
    'fill' => true,
    'clip' => false,
    'line-height' => 1.25,
    'bgcolor' => false,
    'fgcolor' => 
    array (
      'R' => 0,
      'G' => 0,
      'B' => 0,
    ),
    'strokecolor' => 
    array (
      'R' => 0,
      'G' => 0,
      'B' => 0,
    ),
    'align' => '',
    'listtype' => '',
    'text-indent' => 0,
    'text-transform' => '',
    'border' => 
    array (
    ),
    'dir' => 'ltr',
  ),
)

We previously returned an array with a key of 0; we are now returning an empty array. Hence we are getting this error.

Elsewhere in the code, I see dependencies on other elements in this array.

I can "fix" the PHP errors by replacing return array() in the change with return array(array('tag'=>false,'value'=>'')).

However, there may be subtle functional changes that I'm missing.

nicolaasuni added a commit that referenced this issue Mar 20, 2024
@nicolaasuni
Copy link
Member

Please check the version 6.7.3 it should be fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants