mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-09-15 04:06:24 +00:00
:octocat: fixed a rare code length overflow issue
This commit is contained in:
+1
-1
@@ -195,7 +195,7 @@ final class QRData{
|
||||
|
||||
// guess the version number within the given range
|
||||
for($version = $this->options->versionMin; $version <= $this->options->versionMax; $version++){
|
||||
if($total <= $this->maxBitsForEcc[$version]){
|
||||
if($total <= $this->maxBitsForEcc[$version] - 4){
|
||||
return new Version($version);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ use chillerlan\QRCode\Common\{EccLevel, MaskPattern, Mode, Version};
|
||||
use chillerlan\QRCode\Data\{QRCodeDataException, QRData, QRDataModeInterface, QRMatrix};
|
||||
use chillerlan\QRCode\QROptions;
|
||||
use chillerlan\QRCodeTest\QRMaxLengthTrait;
|
||||
use PHPUnit\Framework\{ExpectationFailedException, TestCase};
|
||||
use Exception, Generator;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use function array_map, hex2bin, mb_strlen, mb_substr, sprintf, str_repeat, strlen, substr;
|
||||
|
||||
/**
|
||||
@@ -187,7 +187,13 @@ abstract class DataInterfaceTestAbstract extends TestCase{
|
||||
|
||||
$minimumVersionNumber = $this->QRData->getMinimumVersion()->getVersionNumber();
|
||||
|
||||
$this::assertSame($version->getVersionNumber(), $minimumVersionNumber);
|
||||
try{
|
||||
$this::assertSame($version->getVersionNumber(), $minimumVersionNumber);
|
||||
}
|
||||
catch(ExpectationFailedException $e){
|
||||
$this::assertSame(($version->getVersionNumber() + 1), $minimumVersionNumber, 'safety margin');
|
||||
}
|
||||
|
||||
// verify the encoded data
|
||||
$this::assertSame($this->dataMode::DATAMODE, $bitBuffer->read(4));
|
||||
$this::assertSame($str, $this->dataMode::decodeSegment($bitBuffer, $minimumVersionNumber));
|
||||
|
||||
Reference in New Issue
Block a user