fpvectorial: Fix possible word overflow in wmfVectorialWriter.PrepareScaling

git-svn-id: branches/fixes_2_0@64011 -
This commit is contained in:
mattias 2020-10-15 11:20:45 +00:00
parent d6eb3f3a05
commit 886ab5f015

View File

@ -337,15 +337,24 @@ begin
end; end;
procedure TvWMFVectorialWriter.PrepareScaling(APage: TvVectorialPage); procedure TvWMFVectorialWriter.PrepareScaling(APage: TvVectorialPage);
const
MAXINT16 = 32767;
var
maxx, maxy: Double;
begin begin
FScalingFactor := round(ONE_INCH * 100); // 1 logical unit is 1/100 mm = 10 µm FScalingFactor := round(ONE_INCH * 100); // 1 logical unit is 1/100 mm = 10 µm
FLogicalMaxX := trunc(APage.Width * FScalingFactor); maxx := APage.Width * FScalingFactor;
FLogicalMaxY := trunc(APage.Height * FScalingFactor); maxy := APage.Height * FScalingFactor;
// wmf is 16 bit only! --> reduce magnification if numbers get too big // wmf is 16 bit only! --> reduce magnification if numbers get too big
if Max(FLogicalMaxX, FLogicalMaxY) > $7FFF then begin if Max(maxx, maxy) > MAXINT16 then
FScalingFactor := trunc($7FFF / Max(APage.Width, APage.Height)); begin
FLogicalMaxX := trunc(APage.Width * FScalingFactor); FScalingFactor := trunc(MAXINT16 / Max(APage.Width, APage.Height));
FLogicalMaxY := trunc(APage.Height * FScalingFactor); FLogicalMaxX := word(trunc(APage.Width * FScalingFactor));
FLogicalMaxY := word(trunc(APage.Height * FScalingFactor));
end else
begin
FLogicalMaxX := trunc(maxx);
FLogicalMaxY := trunc(maxy);
end; end;
end; end;