bugThe FreeType Project - Bugs: bug #51816, Realloc from 0 count does zero of...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #51816: Realloc from 0 count does zero of memory twice

Submitter:  None
Submitted:  Mon 21 Aug 2017 09:19:36 PM UTC
   
 
Severity:  3 - Normal Item Group:  Incorrect behaviour
Status:  Fixed Privacy:  Public
Assigned to:  wl Open/Closed:  Closed
Planned Release:  2.9.1

Jump to the original submission

Wed 02 May 2018 08:55:45 PM UTC, comment #6: 

Sorry for the delay.

Yes in -current git the original issue with the Sazanami Gothic font under OpenBSD seems to be solved.

I haven't had an occasion to try this under Linux with valgrind nor to look closer at your fix.


Matthieu Herrb <mherrb>
Sun 22 Apr 2018 03:35:17 PM UTC, comment #5: 

Alexei and I have just fixed a bug in bitmap emboldening – I believe the issue is now really fixed.  Can you please test the current git and check whether my assumption is correct?

Werner LEMBERG <wl>
Group administrator
Mon 02 Apr 2018 03:13:51 PM UTC, comment #4: 

What I need is a recipe to reproduce this with one of the FreeType demo programs.  In case this doesn't work, I need something else that I can debug, ideally a MWE on the console.  Obviously, neither xterm nor Firefox belong into this category...

Werner LEMBERG <wl>
Group administrator
Sun 11 Mar 2018 05:09:12 PM UTC, comment #3: 

Hi,

apparently this change is wrong:
https://marc.info/?l=openbsd-tech&m=152073717024103&w=2


Matthieu Herrb <mherrb>
Wed 23 Aug 2017 10:16:31 PM UTC, comment #2: 

I submitted that... Thanks for putting the fix in.

Patrick J. Daly <pjdaly>
Tue 22 Aug 2017 06:43:22 AM UTC, comment #1: 

Thanks a lot for your analysis and fix.  I've applied the patch to the git repository.

Werner LEMBERG <wl>
Group administrator
Mon 21 Aug 2017 09:19:36 PM UTC, original submission:  

While debugging I noticed the memory from a ft_mem_realloc() gets
zeroed twice when called with current count 0. With non-zero current
count, the memory->realloc() callout is done but with zero current count,
ft_mem_alloc() is called instead of memory->alloc().

I downloaded and looked at version 2.8 and the ft_mem_alloc is there as well.

I did some light testing with this change and output checksums were the same.

177c177,180
<       block = ft_mem_alloc( memory, new_count*item_size, &error );
---

>       /*block = ft_mem_alloc( memory, new_count*item_size, &error );*/
>       block = memory->alloc( memory, new_count*item_size );
>       if ( block == NULL )
>         error = FT_THROW( Out_Of_Memory );




    ......
    else if ( new_count > FT_INT_MAX/item_size )
    {
      error = FT_THROW( Array_Too_Large );
    }
    else if ( cur_count == 0 )
    {
      FT_ASSERT( block == NULL );

      block = ft_mem_alloc( memory, new_count*item_size, &error );  <--- causes double zeroing
    }
    else
    {
      FT_Pointer  block2;
      FT_Long     cur_size = cur_count*item_size;
      FT_Long     new_size = new_count*item_size;


      block2 = memory->realloc( memory, cur_size, new_size, block );
      if ( block2 == NULL )
        error = FT_THROW( Out_Of_Memory );
      else
        block = block2;
    }

#7  0x082061bb in FRSAlloc (pPDIstate=0xefc126f8, size=1104, file=0x888bf50 "../freetype2/ftsystem.c", line=132) at ../pdi/fntsockt.c:506
#8  0x08299193 in ft_alloc (memory=0xefc14f18, size=1104) at ../freetype2/ftsystem.c:132
#9  0x08254162 in ft_mem_qalloc (memory=0xefc14f18, size=1104, p_error=0xffffc288) at ../freetype2/ftutil.c:108
#10 0x082540fc in ft_mem_alloc (memory=0xefc14f18, size=1104, p_error=0xffffc2b0) at ../freetype2/ftutil.c:87
                  ^^^^^^^^^^^ Zeros memory it gets from ft_mem_qalloc()
#11 0x082543d4 in ft_mem_qrealloc (memory=0xefc14f18, item_size=92, cur_count=0, new_count=12, block=0x0, p_error=0xffffc2fc) at
                  ^^^^^^^^^^^^^^ Since this doesn't call ft_alloc() directly, memory is zeroed twice.
../freetype2/ftutil.c:294
#12 0x082541ff in ft_mem_realloc (memory=0xefc14f18, item_size=92, cur_count=0, new_count=12, block=0x0, p_error=0xffffc374) at
                   ^^^^^^^^^^^ Zeros memory it gets from ft_mem_qrealloc()


Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mherrb (Posted a comment)
  • -email is unavailable- added by pjdaly (Posted a comment)
  • -email is unavailable- added by wl (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-04-22 wl Planned Release2.8.1 2.9.1
    2017-08-22 wl StatusNone Fixed
        Assigned toNone wl
        Open/ClosedOpen Closed
        Planned ReleaseNone 2.8.1

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code