documentcloud / pdfshaver

Shave pages off of PDFs as images
MIT License
58 stars 9 forks source link

PDFShaver segfaults on OSX when sqlite3 gem is loaded #1

Closed knowtheory closed 5 years ago

knowtheory commented 9 years ago

¯_(ツ)_/¯

knowtheory commented 9 years ago

works fine on linux. Quartz's font loader seems to have some sort of conflict when loading the sqlite3 gem's code

nathanstitt commented 9 years ago

An extra strange bit about the segfault is that it only occurs in a forked child process. The parent remains unaffected.

This will succeed:

fork{ PDFShaver::Document.new('test.pdf').pages } }

But this will segfault (on OS X 10.10 Yosemite ):

require 'sqlite3'
fork{  PDFShaver::Document.new('test.pdf').pages } }

After sqlite3 is required, any use of PDFShaver inside a forked process will segfault, however the parent will remain unaffected.

The backtrace from the segfault:

#18 0x00007fff909726af in CGFontCreateWithDataProvider ()
#19 0x000000010ae1c045 in CQuartz2D::CreateFont(unsigned char const*, unsigned int) at /private/tmp/pdfium-JW8sEc/out/Release/../../core/src/fxge/apple/fx_quartz_device.cpp:57
#20 0x000000010adb0267 in CPDF_Type1Font::LoadGlyphMap() at /private/tmp/pdfium-JW8sEc/out/Release/../../core/src/fpdfapi/fpdf_font/fpdf_font.cpp:1142
#21 0x000000010adafc89 in CPDF_SimpleFont::LoadCommon() at /private/tmp/pdfium-JW8sEc/out/Release/../../core/src/fpdfapi/fpdf_font/fpdf_font.cpp:988
#22 0x000000010adb016b in CPDF_Type1Font::_Load() at /private/tmp/pdfium-JW8sEc/out/Release/../../core/src/fpdfapi/fpdf_font/fpdf_font.cpp:1068
#23 0x000000010adae9a3 in CPDF_Font::Load() at /private/tmp/pdfium-JW8sEc/out/Release/../../core/src/fpdfapi/fpdf_font/fpdf_font.cpp:494
#24 0x000000010adae894 in CPDF_Font::CreateFontF(CPDF_Document*, CPDF_Dictionary*) at /private/tmp/pdfium-JW8sEc/out/Release/../../core/src/fpdfapi/fpdf_font/fpdf_font.cpp:478
#25 0x000000010adc1626 in CPDF_DocPageData::GetFont(CPDF_Dictionary*, int) at /private/tmp/pdfium-JW8sEc/out/Release/../../core/src/fpdfapi/fpdf_page/fpdf_page_doc.cpp:307
#26 0x000000010add08ab in CPDF_StreamContentParser::GetString(unsigned int) [inlined] at /private/tmp/pdfium-JW8sEc/out/Release/../../core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp:1216
#27 0x000000010add0809 in CPDF_StreamContentParser::Handle_SetFont() at /private/tmp/pdfium-JW8sEc/out/Release/../../core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp:1176
#28 0x000000010adcabfc in CPDF_StreamContentParser::OnOperator(char const*) at /private/tmp/pdfium-JW8sEc/out/Release/../../core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp:341
#29 0x000000010add29b8 in CPDF_StreamContentParser::Parse(unsigned char const*, unsigned int, unsigned int) at /private/tmp/pdfium-JW8sEc/out/Release/../../core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp:62
#30 0x000000010add574d in CPDF_ContentParser::Continue(IFX_Pause*) at /private/tmp/pdfium-JW8sEc/out/Release/../../core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp:1091
#31 0x000000010adbc0df in CPDF_PageObjects::ContinueParse(IFX_Pause*) [inlined] at /private/tmp/pdfium-JW8sEc/out/Release/../../core/src/fpdfapi/fpdf_page/fpdf_page.cpp:704
#32 0x000000010adbc0cf in CPDF_Page::ParseContent(CPDF_ParseOptions*, int) at /private/tmp/pdfium-JW8sEc/out/Release/../../core/src/fpdfapi/fpdf_page/fpdf_page.cpp:906
#33 0x000000010ad5c9b4 in FPDF_LoadPage at /private/tmp/pdfium-JW8sEc/out/Release/../../fpdfsdk/src/fpdfview.cpp:311
#34 0x000000010ad5b6a9 in Page::load(Document*, int) ()
copiousfreetime commented 9 years ago

Since sqlite is also part of OSX (CoreData) there is the possibility of something like this happening. I have a similar issue in Amalgalite https://github.com/copiousfreetime/amalgalite/blob/master/lib/amalgalite/sqlite3/version.rb#L41-L55

knowtheory commented 5 years ago

I think we got this sorted out!