1modm / petereport

PeTeReport is an open-source application vulnerability reporting tool.

Home Page:https://1modm.github.io/petereport/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error 500 when generating pdf report

ky0112 opened this issue · comments

When generating large PDF report with a lot of base 64 image in it, it will hit error 500 during the generating pdf report process.

Here is the debug log
image

2022-05-02 00_35_47-RuntimeError at _report_download_pdf_7 - Brave

Traceback:
Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/report/download/pdf/7

Django Version: 3.2.5
Python Version: 3.8.10
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'martor',
'django_bleach',
'preport']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']

Traceback (most recent call last):
File "/home/admin123/.local/share/virtualenvs/petereport-_1hU1HQ3/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/home/admin123/.local/share/virtualenvs/petereport-_1hU1HQ3/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/admin123/.local/share/virtualenvs/petereport-_1hU1HQ3/lib/python3.8/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/opt/petereport/app/preport/views.py", line 941, in reportdownloadpdf
output_pypandoc = pypandoc.convert_text(final_markdown_output, to='pdf', outputfile=pdf_file_output, format='md', extra_args=['-H', PDF_HEADER_FILE, '--from', 'markdown+yaml_metadata_block+raw_html', '--template', PETEREPORT_LATEX_FILE, '--table-of-contents', '--toc-depth', '4', '--number-sections', '--highlight-style', 'breezedark', '--filter', 'pandoc-latex-environment', '--listings'])
File "/home/admin123/.local/share/virtualenvs/petereport-_1hU1HQ3/lib/python3.8/site-packages/pypandoc/init.py", line 100, in convert_text
return _convert_input(source, format, 'string', to, extra_args=extra_args,
File "/home/admin123/.local/share/virtualenvs/petereport-_1hU1HQ3/lib/python3.8/site-packages/pypandoc/init.py", line 321, in _convert_input
raise RuntimeError(

Exception Type: RuntimeError at /report/download/pdf/7
Exception Value: Pandoc died with exitcode "43" during conversion: b'libpng error: IDAT: invalid stored block lengths\nlibpng error: IDAT: invalid stored block lengths\nlibpng error: IDAT: invalid stored block lengths\nError producing PDF.\n!pdfTeX error: pdflatex: libpng: internal error\n ==> Fatal error occurred, no output PDF file produced!\n\n'

Thanks

commented

Hi @ky0112,

I was taking a look into this issue, and unfortunately the issue is generated by libpng and pandoc (the tools used to convert the images and create the reports). My only suggestion is to try some workarounds like use jpg instead of png to see if this error is not generated, or use the media file storage option (instead of storage in DB) to see if works. For that you need to set 'martor_upload_method': 'MEDIA' and in django 'debug': True

https://1modm.github.io/petereport/configuration/#markdown-configuration

Thanks

Hi 1modm,

After setting 'martor_upload_method': 'MEDIA' and 'debug': True in app/config/petereport_config.py it get another error. Following is the traceback
2022-05-05 10_49_10-Window

image

2022-05-05 10_51_10-Window

`Environment:

Request Method: GET
Request URL: http://10.115.8.11:8000/report/download/pdf/2

Django Version: 3.2.5
Python Version: 3.8.10
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'martor',
'django_bleach',
'preport']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']

Traceback (most recent call last):
File "/home/admin123/.local/share/virtualenvs/petereport-_1hU1HQ3/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/home/admin123/.local/share/virtualenvs/petereport-_1hU1HQ3/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/admin123/.local/share/virtualenvs/petereport-_1hU1HQ3/lib/python3.8/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/opt/petereport/app/preport/views.py", line 942, in reportdownloadpdf
output_pypandoc = pypandoc.convert_text(final_markdown_output, to='pdf', outputfile=pdf_file_output, format='md', extra_args=['-H', PDF_HEADER_FILE, '--from', 'markdown+yaml_metadata_block+raw_html', '--template', PETEREPORT_LATEX_FILE, '--table-of-contents', '--toc-depth', '4', '--number-sections', '--highlight-style', 'breezedark', '--filter', 'pandoc-latex-environment', '--listings', '--no-check-certificate'])
File "/home/admin123/.local/share/virtualenvs/petereport-_1hU1HQ3/lib/python3.8/site-packages/pypandoc/init.py", line 100, in convert_text
return _convert_input(source, format, 'string', to, extra_args=extra_args,
File "/home/admin123/.local/share/virtualenvs/petereport-_1hU1HQ3/lib/python3.8/site-packages/pypandoc/init.py", line 321, in _convert_input
raise RuntimeError(

Exception Type: RuntimeError at /report/download/pdf/2
Exception Value: Pandoc died with exitcode "2" during conversion: b'Unknown option --no-check-certificate.\nTry pandoc --help for more information.\n'
`

Thanks

commented

@ky0112 try to install pandoc > 2.10, for example:

wget https://github.com/jgm/pandoc/releases/download/2.18/pandoc-2.18-1-amd64.deb
dpkg -i pandoc-2.18-1-amd64.deb

@1modm it works

Thank you