From 5596537f8fad108219e77bad960f9f528e2414fd Mon Sep 17 00:00:00 2001 From: Stephen Sigwart Date: Fri, 12 Aug 2022 03:29:02 -0400 Subject: [PATCH] Fix Infinite Loop in Multicell with Auto Page Breaks Off (#473) The updated places that used `AcceptPageBreak` assumed that a page break was added and increased X by the margin. However, if the break wasn't added, it would put the text further to the right to the point that the width because so small or negative and no characters fit, causing an infinite loop. Co-authored-by: Nicola Asuni --- tcpdf.php | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/tcpdf.php b/tcpdf.php index 02f7aaa0..85b790d6 100644 --- a/tcpdf.php +++ b/tcpdf.php @@ -6495,14 +6495,16 @@ public function Write($h, $txt, $link='', $fill=false, $align='', $ln=false, $st $shy = false; // account for margin changes if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) { - $this->AcceptPageBreak(); - if ($this->rtl) { - $this->x -= $margin['R']; - } else { - $this->x += $margin['L']; + if ($this->AcceptPageBreak()) + { + if ($this->rtl) { + $this->x -= $margin['R']; + } else { + $this->x += $margin['L']; + } + $this->lMargin += $margin['L']; + $this->rMargin += $margin['R']; } - $this->lMargin += $margin['L']; - $this->rMargin += $margin['R']; } $w = $this->getRemainingWidth(); $wmax = ($w - $this->cell_padding['L'] - $this->cell_padding['R']); @@ -6700,14 +6702,16 @@ public function Write($h, $txt, $link='', $fill=false, $align='', $ln=false, $st } // account for margin changes if ((($this->y + $this->lasth) > $this->PageBreakTrigger) AND ($this->inPageBody())) { - $this->AcceptPageBreak(); - if ($this->rtl) { - $this->x -= $margin['R']; - } else { - $this->x += $margin['L']; + if ($this->AcceptPageBreak()) + { + if ($this->rtl) { + $this->x -= $margin['R']; + } else { + $this->x += $margin['L']; + } + $this->lMargin += $margin['L']; + $this->rMargin += $margin['R']; } - $this->lMargin += $margin['L']; - $this->rMargin += $margin['R']; } $w = $this->getRemainingWidth(); $wmax = $w - $this->cell_padding['L'] - $this->cell_padding['R'];