reingart / pyfpdf_googlecode

Automatically exported from code.google.com/p/pyfpdf
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Integer division causes divide by zero error when units is 'in'. Errant code identified, but no patch supplied. #78

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Specify 'in' as the unit.
2. Set font size less than 72 (using 'set_font()' or 'set_font_size()')
3. Generate PDF.

What is the expected output? What do you see instead?
I expect to receive a PDF. I get the Python exception: type 
'exceptions.ZeroDivisionError'

What version of the product are you using? On what operating system?
FPDF v1.7.1. running under Python v2.6.6

Please provide any additional information below.
The problem is that when an FPDF object is created, 'self.k' is set to an 
integer whenever 'pt' or 'in' is supplied as the 'unit'. (See lines 81-88 of 
fpdf.py) In various other places in the code, 'self.k' is used as a divisor 
with an integer dividend. This results in an integer division and is the cause 
of the problem. For a concrete example: Create an FPDF object with 'in' as the 
'unit'. 'self.k' will be set to 72 (notice that this is an integer). Now call 
'set_font_size(36)'. Notice that you are passing an integer as the size and 
that the integer is less than 72. When the font_size is calculated (on line 
584), Python performs the integer division '36/72' which results in 'font_size' 
being set to 0. With font_size==0, the ZeroDivisionError occurs later on in the 
program.

Note that if you 'set_font_size(n)' where n >= 72, the program will not raise 
an exception, but the value calculated for font_size will not be correct 
(unless n%72==0).

Original issue reported on code.google.com by lgilb...@petvacclinic.com on 28 Aug 2014 at 5:19

GoogleCodeExporter commented 9 years ago
Same as Issue 36? (which has proposed patches)

Original comment by vadm...@gmail.com on 31 Dec 2014 at 10:11

GoogleCodeExporter commented 9 years ago

Original comment by reingart@gmail.com on 2 Jan 2015 at 11:43