tecnickcom / TCPDF

Official clone of PHP library to generate PDF documents and barcodes
https://tcpdf.org
Other
4.22k stars 1.52k forks source link

Fix Infinite Loop in Multicell with Auto Page Breaks Off #473

Closed ssigwart closed 2 years ago

ssigwart commented 2 years ago

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.

Example File

<?php

require_once('tcpdf_include.php');

class MYPDF extends TCPDF
{
    public function crash()
    {
        $width = 140;
        $val = '';
        for ($i = 1; $i <= 100; $i++)
            $val .= "Line $i\n";
        $this->MultiCell($width, 10, $val, 1, 'L');
    }
}

$pdf = new MYPDF('P', 'mm', 'A4', true, 'UTF-8', false);
$pdf->setMargins(10, 10, 10);
$pdf->setCellMargins(10, 0, 10, 0);
$pdf->setAutoPageBreak(false);
$pdf->setFont('helvetica', '', 12);
$pdf->AddPage();
$pdf->crash();
$pdf->Output('file.pdf', 'I');
CLAassistant commented 2 years ago

CLA assistant check
All committers have signed the CLA.

ssigwart commented 2 years ago

Thanks for merging this, @nicolaasuni!