This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

windres bug.


Hello,

I have identified a bug within windres v2.11.90 where it is not
correctly calculating the HEADER_SIZE (offset 4 bytes into the resource
header).  I found this after compiling the windres on a i386 linux box
for use with the Borland Kylix to build RES files that Kylix needs.

The problem shows up when building BITMAPs (I only tested it with
bitmaps), if the name of the bitmap is an EVEN number of bytes, the
res_id header size is improperly calculated.  The effect shows up with
an RC file as follows (the only correct header written is for 'RITE1'):

================================================
 
LANGUAGE 9, 4
 
EFT1 BITMAP MOVEABLE DISCARDABLE "../kylix/images/left1.bmp"
 
EFT2 BITMAP MOVEABLE DISCARDABLE "../kylix/images/left2.bmp"
 
RITE1 BITMAP MOVEABLE DISCARDABLE "../kylix/images/right1.bmp"
 
SRITE2 BITMAP MOVEABLE DISCARDABLE
"../kylix/images/right2.bmp"                
================================================


The problem is within the binutils/resres.c in two functions of
write_res_header() & res_align_file() which currently reads:


================================================
/* Write a resource header */
static void
write_res_header (datasize, type, name, resinfo)
     unsigned long datasize;
     const struct res_id *type;
     const struct res_id *name;
     const struct res_res_info *resinfo;
{
  struct res_hdr reshdr;
  reshdr.data_size = datasize;
  reshdr.header_size = 24 + get_id_size (type) + get_id_size (name);

  res_align_file ();
  write_res_data (&reshdr, sizeof (reshdr), 1);
  write_res_id (type);
  write_res_id (name);

  res_align_file ();

  write_res_info (resinfo);
  res_align_file ();
}

.
.
.

/* align file on DWORD boundary */
static void
res_align_file (void)
{
  if (fseek (fres, ftell (fres) % 4, SEEK_CUR) != 0)
    fatal ("%s: %s: unable to align file", program_name, filename);
}
================================================


With an even number of bytes in the unicode name the DWORD computation
of the header size fails.  I have corrected this problem with rewriting
the write_res_header to:


================================================
/* Write a resource header */
static void
write_res_header (datasize, type, name, resinfo)
     unsigned long datasize;
     const struct res_id *type;
     const struct res_id *name;
     const struct res_res_info *resinfo;
{
  struct res_hdr reshdr;
  reshdr.data_size = datasize;
  reshdr.header_size = 24 + get_id_size (type) + get_id_size (name);

  	/* TomW: align the header size to DWORD boundry. */
  reshdr.header_size += reshdr.header_size % 4;

  res_align_file ();

  write_res_data (&reshdr, sizeof (reshdr), 1);
  write_res_id (type);
  write_res_id (name);

  res_align_file ();

  write_res_info (resinfo);
  res_align_file ();
}
================================================

Would someone please pass this info to the maintainer of the windres
package?  I would also like to know when the fix is released? I am
writing a HOWTO for the Kylix programmers so that they can "wean"
themselves of the need to use windoze to write these resource files for
kylix and would like to time the paper to the release.

Thank you,

TomW


-- 
Tom Walsh - WN3L - Embedded Systems Consultant
http://openhardware.net, http://cyberiansoftware.com
"Windows? No thanks, I have work to do..."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]