From dev-return-56934-archive-asf-public=cust-asf.ponee.io@pdfbox.apache.org Thu Jun 7 22:25:05 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id AE85D18067B for ; Thu, 7 Jun 2018 22:25:04 +0200 (CEST) Received: (qmail 458 invoked by uid 500); 7 Jun 2018 20:25:03 -0000 Mailing-List: contact dev-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pdfbox.apache.org Delivered-To: mailing list dev@pdfbox.apache.org Received: (qmail 447 invoked by uid 99); 7 Jun 2018 20:25:03 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jun 2018 20:25:03 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 49343180840 for ; Thu, 7 Jun 2018 20:25:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -110.311 X-Spam-Level: X-Spam-Status: No, score=-110.311 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01, USER_IN_DEF_SPF_WL=-7.5, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id FCEpnluNBZKT for ; Thu, 7 Jun 2018 20:25:02 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id CBB5C5F5B2 for ; Thu, 7 Jun 2018 20:25:01 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 4448CE0E4B for ; Thu, 7 Jun 2018 20:25:01 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 8258A217F1 for ; Thu, 7 Jun 2018 20:25:00 +0000 (UTC) Date: Thu, 7 Jun 2018 20:25:00 +0000 (UTC) From: "Glen Peterson (JIRA)" To: dev@pdfbox.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (PDFBOX-4242) Fontbox does not close file descriptor when loading fonts. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/PDFBOX-4242?page=3Dcom.atlassia= n.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D165= 05207#comment-16505207 ]=20 Glen Peterson commented on PDFBOX-4242: --------------------------------------- PDType0Font is *not* closing it. I looked again here: [https://github.com/apache/pdfbox/blob/trunk/pdfbox/src/main/java/org/apac= he/pdfbox/pdmodel/font/PDType0Font.java#L112] {{ if (closeOnSubset)}} {{ {}} {{=C2=A0 =C2=A0 if (embedSubset)}} {{=C2=A0 =C2=A0 {}} {{=C2=A0 =C2=A0 =C2=A0 =C2=A0 this.ttf =3D ttf;}} {{=C2=A0 =C2=A0 }}} {{=C2=A0 =C2=A0 else}} {{=C2=A0 =C2=A0 {}} {{=C2=A0 =C2=A0 =C2=A0 =C2=A0 // the TTF is fully loaded and it is save to = close the underlying data source}} {{=C2=A0 =C2=A0 =C2=A0 =C2=A0 ttf.close();}} {{=C2=A0 =C2=A0 }}} {{ }}} So it's only closed automatically if closeOnSubset=3Dtrue and embedSubset= =3Dfalse.=C2=A0 They are both true=C2=A0when using the load() method I used= . To close them, you'd probably have to keep a list of open fonts, and close = them when the document is closed.=C2=A0 I=C2=A0can=C2=A0make my code do tha= t.=C2=A0 Thanks for talking me through this - it really helped! > Fontbox does not close file descriptor when loading fonts. > ---------------------------------------------------------- > > Key: PDFBOX-4242 > URL: https://issues.apache.org/jira/browse/PDFBOX-4242 > Project: PDFBox > Issue Type: Bug > Components: FontBox > Affects Versions: 2.0.9 > Reporter: Glen Peterson > Priority: Major > Labels: file_leak > > My app has been getting "java.io.FileNotFoundException (No file descripto= rs available)" and I've confirmed that=C2=A0it's because fontbox isn't clos= ing it's file descriptors. > In=C2=A0org.apache.fontbox.ttf.TTFParser there's this method: > {{public TrueTypeFont parse(File ttfFile) throws IOException {}} > {{=C2=A0 RAFDataStream raf =3D new RAFDataStream(ttfFile, "r");}} > {{=C2=A0 try {}} > {{=C2=A0 =C2=A0 return this.parse((TTFDataStream)raf);}} > {{=C2=A0 } catch (IOException var4) {}} > {{=C2=A0 =C2=A0 // close only on error (file is still being accessed lat= er)}} > {{=C2=A0 =C2=A0 raf.close();}} > {{=C2=A0 =C2=A0 throw var4;}} > {{}}} > {{}}} > I would have expected to see the close() in a finally block so that the f= ile is always closed, not just on exceptions. Presumably, you can keep it i= n memory without leaving the file descriptor open? > {{public TrueTypeFont parse(File ttfFile) throws IOException {}} > {{=C2=A0 RAFDataStream raf =3D new RAFDataStream(ttfFile, "r");}} > {{=C2=A0 try {}} > {{=C2=A0 =C2=A0 return this.parse((TTFDataStream)raf);}} > {{=C2=A0 } catch (IOException var4) {}}{{=C2=A0 =C2=A0 raf.close();}} > {{=C2=A0 =C2=A0 throw var4;}} > {{=C2=A0 } finally {}} > {{=C2=A0 =C2=A0 raf.close();}} > {{}}} > {{}}} > I tried performing this in a lazy initialization, but it blew up: > java.lang.RuntimeException: java.io.IOException: The TrueType font null d= oes not contain a 'cmap' tableCaused by: java.io.IOException: The TrueType = font null does not contain a 'cmap' table > at org.apache.fontbox.ttf.TrueTypeFont.getUnicodeCmapImpl(TrueTypeFont.= java:548) > at org.apache.fontbox.ttf.TrueTypeFont.getUnicodeCmapLookup(TrueTypeFon= t.java:528) > at org.apache.fontbox.ttf.TrueTypeFont.getUnicodeCmapLookup(TrueTypeFon= t.java:514) > at org.apache.fontbox.ttf.TTFSubsetter.(TTFSubsetter.java:91) > at org.apache.pdfbox.pdmodel.font.TrueTypeEmbedder.subset(TrueTypeEmbed= der.java:321) > at org.apache.pdfbox.pdmodel.font.PDType0Font.subset(PDType0Font.java:2= 39) > at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1271) > Thoughts? > Thanks for PDFBox - it's been really helpful! -- This message was sent by Atlassian JIRA (v7.6.3#76005) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org For additional commands, e-mail: dev-help@pdfbox.apache.org