0
votes

I created a program that according to a string it creates a BMP file.

On a slackware machine:

  • i686;
  • little endian;
  • lang = en_US;

The image is generated perfectly with the result of file img.bmp being:

  • 'img.bmp: PC bitmap, Windows 3.x format, 168 x -168 x 24'

And the result of file -si img.bmp being:

  • 'img.bmp: image/x-ms-bmp; charset=binary'

On a Xubuntu:

  • i686;
  • little endian;
  • lang = en_US;

The image is corrupt with 2 more bytes than the working one and file img.bmp gives:

  • 'img.bmp: data'

And file -si img.bmp gives:

  • 'img.bmp: application/octet-stream; charset=binary'...

Both the source files are in 'ASCII text'.

The encoding of the working binary executable is:

  • 'ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), not stripped'.

The encoding of working binary executable (but generates corrupt image) is:

  • 'ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=07dc7b384509e7a6b2d1f87460998b00fe050866, not stripped'.

I'm trying to understand why I can view the image generated on my slackware VM but I can't view it on Xubuntu...

1
The encoding of the source code of course has nothing to do with the encoding of the output of running the compiled program. You probably have some bug where you rely on undefined behavior (perhaps struct packing), but of course it's impossible to say without the code.unwind
Ah yes! Perfect, that was the problem. I knew that the encoding of the source code had nothing to do with the output of the running compiled program, but i was afraid i was forgetting something.Vcoder

1 Answers

0
votes

I solved the problem by doing:

#pragma pack(push, 2)

struct goes here

#pragma pack(pop)

Thanks to unwind.