Post without Account — your post will be reviewed, and if appropriate, posted under Anonymous. You can also use this link to report any problems registering or logging in.

RT 122371 - corrupted font object

  • 2 Replies
  • 1315 Views
*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 417
    • View Profile
RT 122371 - corrupted font object
« July 05, 2017, 09:01:09 PM »
Wed Jul 05 20:51:52 2017 philperry [...] hvc.rr.com - Ticket created
Subject:    corrupted font object
Date:    Wed, 5 Jul 2017 20:50:36 -0400

I'm running the old examples/021_synfonts against PDF::API2 2.032 (just released), on Win7. The first font (/Times-Roman/) reports an error on PDF::API2::Basic::PDF::File line 933 ($objind->is_obj($self)) that the method can't be called. I traced this down to a newly-added "weaken" statement at line 870 in sub out_obj(), which apparently is causing a corefont object to be empty (at least, for Times-Roman). Commenting out that line lets everything run, but I'm not sure if that's safe or has undesirable interactions with other things.

By the way, to run 021_synfonts all the way through, PDF::API2::Resource::Font::CoreFont:: bankgothic needs a fix: change sub
fontdata
to sub data.

I was working on a utility for corefonts when the /weaken/ changes came out, and encountered the same problem (with Times-Roman, but not Helvetica or Helvetica-Bold), so I suspect it's not unique to 021_synfonts. It may be a flaw in the Times-Roman font or its supporting files.

*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 417
    • View Profile
Re: RT 122371 - corrupted font object
« Reply #1: July 06, 2017, 11:48:22 AM »
Thu Jul 06 10:40:20 2017 steve [...] deefs.net - Correspondence added

Thanks for the bug reports.

On Wed Jul 05 20:51:52 2017, philperry@hvc.rr.com wrote:
Quote
I'm running the old examples/021_synfonts against PDF::API2 2.032 (just released), on Win7. The first font (/Times-Roman/) reports an error on PDF::API2::Basic::PDF::File line 933 ($objind->is_obj($self)) that the method can't be called. I traced this down to a newly-added "weaken" statement at line 870 in sub out_obj(), which apparently is causing a corefont object to be empty (at least, for Times-Roman). Commenting out that line lets everything run, but I'm not sure if that's safe or has undesirable interactions with other things.

The idea behind using "weaken" is to eliminate circular references, which cause memory leaks in Perl.  PDF::API2 is/was full of them, and the code that's intended to catch them wasn't working (try using Devel::Cycle's find_cycle() function on a PDF::API2 object either before or after calling stringify() or end(), or run t/circular-references.t on 2.031 or earlier).

In order for this to work, when there are two references in a structure to the same object, weaken needs to be called on the one that's going to go out of scope first.  Otherwise, the other reference becomes undef while it could still be needed, which is what you saw.

I've been trying unsuccessfully to recreate the circumstances where the weaken call was necessary in out_obj and add_obj this morning.  I think some of the other weaken calls may be doing the job, so I've commented out both of them.  I've also added a test to ensure that this particular case stays fixed in the future.
 
Quote
By the way, to run 021_synfonts all the way through, PDF::API2::Resource::Font::CoreFont:: bankgothic needs a fix: change sub
fontdata to sub data.

Fixed, and covered with a test as well.

Quote
I was working on a utility for corefonts when the /weaken/ changes came out, and encountered the same problem (with Times-Roman, but not Helvetica or Helvetica-Bold), so I suspect it's not unique to 021_synfonts. It may be a flaw in the Times-Roman font or its supporting files.


Helvetica is being added to the PDF in the same scope as the save call, so that's why it worked.  Not sure about Helvetica-Bold -- it theoretically should've had the same issue as the other fonts.
#
Thu Jul 06 10:40:20 2017 The RT System itself - Status changed from 'new' to 'open'
#
Thu Jul 06 10:40:26 2017 steve [...] deefs.net - Status changed from 'open' to 'patched'

*

Offline Phil

  • Global Moderator
  • Sr. Member
  • *****
  • 417
    • View Profile
Re: RT 122371 - corrupted font object
« Reply #2: July 07, 2017, 01:33:52 PM »
Fri Jul 07 11:03:20 2017 steve [...] deefs.net - Status changed from 'patched' to 'resolved'
#
Fri Jul 07 11:03:26 2017 steve [...] deefs.net - Fixed in 2.033 added