Bug#1007234: Test suite fails on all but amd64 arches

2022-03-29 Thread Mathieu Malaterre
Bryan,

On Tue, Mar 29, 2022 at 1:45 PM Mathieu Malaterre  wrote:
>
> Bryan,
>
> On Sat, Mar 26, 2022 at 2:00 AM Bryan Henderson  
> wrote:
> >
> > I don't know familiar you are with debuggers, C, or C arithmetic, so I'm
> > attaching a diagnostic version of the program and will also explain where I
> > think the problem lies in case you want to investigate on your own.

I am going to discard the test-suite result in Debian package.
Something is not quite right on my side.

Compiling netpbm with gcc-10+ubsan gives odd results on my amd64:

== palm-roundtrip.test ==
pamdepth: promoting from black and white to grayscale
pnmcolormap: making histogram...
pnmcolormap: Scanning image 0
pnmcolormap: 20314 colors so far
pnmcolormap: 20314 colors found
pnmcolormap: choosing 256 colors...
pnmremap: 256 colors found in colormap
pmfileio.c:664:26: runtime error: left shift of 128 by 24 places
cannot be represented in type 'int'
pmfileio.c:664:26: runtime error: left shift of 128 by 24 places
cannot be represented in type 'int'
pmfileio.c:664:26: runtime error: left shift of 128 by 24 places
cannot be represented in type 'int'
pmfileio.c:664:26: runtime error: left shift of 128 by 24 places
cannot be represented in type 'int'
palm-roundtrip.test: FAILURE

I am going to /assume/ code is not tested on arch other than amd64, so
I think this is acceptable behavior.


Thanks for your help.



Bug#1007234: Test suite fails on all but amd64 arches

2022-03-29 Thread Mathieu Malaterre
Bryan,

On Sat, Mar 26, 2022 at 2:00 AM Bryan Henderson  wrote:
>
> I don't know familiar you are with debuggers, C, or C arithmetic, so I'm
> attaching a diagnostic version of the program and will also explain where I
> think the problem lies in case you want to investigate on your own.
>
> If you put this .c file in converter/other/pnmtopalm/ and rebuild and run the
> 'palmtopnm' executable that results, it should detect the failure and write
> some useful diagnostic messages.  Tell me what happens.

Thanks !

Here is what I see on my local riscv64/chroot

== palm-roundtrip.test ==
pamdepth: promoting from black and white to grayscale
palmtopnm: Invalid Palm image input.  Header says 30 bytes per row
after uncompressing from 8-bit Packbits, but we counted 4294967069
bytes in a row, before we stopped processing the row
pnmcolormap: making histogram...
pnmcolormap: Scanning image 0
pnmcolormap: 20314 colors so far
pnmcolormap: 20314 colors found
pnmcolormap: choosing 256 colors...
pnmremap: 256 colors found in colormap
palmtopnm: Invalid Palm image input.  Header says 228 bytes per row
after uncompressing from 8-bit Packbits, but we counted 4294967044
bytes in a row, before we stopped processing the row
palm-roundtrip.test: FAILURE


Pay attention that I cannot do any kind of gdb locally:

 % gdb ./converter/other/pnmtopalm/palmtopnm
[...]
(gdb) r
Starting program:
/home/mathieu/debian/netpbm/converter/other/pnmtopalm/palmtopnm
warning: Could not trace the inferior process.
warning: ptrace: Function not implemented
During startup program exited with code 127.


>
> The problem is in function 'readPackBitsRow16'.  The variable 'j' is getting
> too large -- absurdly large, apparently because a bit code that is supposed to
> encode a negative signed integer is being interpreted as a positive unsigned
> one somewhere.  It should not be hard to pinpoint where the arithmetic is
> generating such a a large number.
>
> --
> Bryan Henderson   San Jose, California



Bug#1007234: Test suite fails on all but amd64 arches

2022-03-25 Thread Bryan Henderson
I don't know familiar you are with debuggers, C, or C arithmetic, so I'm
attaching a diagnostic version of the program and will also explain where I
think the problem lies in case you want to investigate on your own.

If you put this .c file in converter/other/pnmtopalm/ and rebuild and run the
'palmtopnm' executable that results, it should detect the failure and write
some useful diagnostic messages.  Tell me what happens.


The problem is in function 'readPackBitsRow16'.  The variable 'j' is getting
too large -- absurdly large, apparently because a bit code that is supposed to
encode a negative signed integer is being interpreted as a positive unsigned
one somewhere.  It should not be hard to pinpoint where the arithmetic is
generating such a a large number.

-- 
Bryan Henderson   San Jose, California/**
 palmtopnm
***
  By Bryan Henderson, San Jose, California, June 2004.

  Inspired by and using methods from Tbmptopnm by Ian Goldberg
  , and Bill Janssen .

  Major fixes and new capability added by Paul Bolle 
  in late 2004 / early 2005.

  Bryan's work is contributed to the public domain by its author.
**/

#include 
#include 

#include "pm_c_util.h"
#include "pnm.h"
#include "shhopt.h"
#include "mallocvar.h"

#include "palm.h"
#include "palmcolormap.h"



enum PalmCompressionType {
COMPRESSION_NONE,
COMPRESSION_RLE,
COMPRESSION_SCANLINE,
COMPRESSION_PACKBITS
};

struct PalmHeader {
unsigned short cols;
unsigned short rows;
unsigned short bytesPerRow;
unsigned short flags;
bool   directColor;
/* The header indicates a direct color raster, either by flag
   (the old way) or by pixel format (the new way)
*/
bool   hasColormap;
bool   hasTransparency;
unsigned char  pixelSizeCode;
unsigned int   pixelSize;
unsigned char  version;
unsigned int   transparentIndex;
enum PalmCompressionType compressionType;
/* version 3 encoding specific */
unsigned char  size;
unsigned char  pixelFormat;
unsigned short density;
unsigned long  transparentValue;
};



struct DirectPixelFormat {
unsigned int redbits;
unsigned int greenbits;
unsigned int bluebits;
};



struct DirectColorInfo {
struct DirectPixelFormat pixelFormat;
ColormapEntrytransparentColor;
};




struct CmdlineInfo {
/* All the information the user supplied in the command line,
   in a form easy for the program to use.
*/
const char * inputFilespec;
unsigned int verbose;
unsigned int rendition;
unsigned int showhist;
unsigned int transparent;
};


static void
parseCommandLine(int argc, const char ** argv,
 struct CmdlineInfo *cmdlineP) {
/*
   Note that the file spec array we return is stored in the storage that
   was passed to us as the argv array.
-*/
optEntry * option_def;
/* Instructions to pm_optParseOptions3 on how to parse our options.
 */
optStruct3 opt;

unsigned int renditionSpec;

unsigned int option_def_index;

MALLOCARRAY_NOFAIL(option_def, 100);

option_def_index = 0;   /* incremented by OPTENTRY */
OPTENT3(0, "verbose", OPT_FLAG, NULL,
>verbose,  0);
OPTENT3(0, "showhist",OPT_FLAG, NULL,
>showhist, 0);
OPTENT3(0, "transparent",OPT_FLAG, NULL,
>transparent, 0);
OPTENT3(0, "rendition",  OPT_UINT, >rendition,
, 0);

opt.opt_table = option_def;
opt.short_allowed = FALSE;  /* We have no short (old-fashioned) options */
opt.allowNegNum = FALSE;  /* We may have parms that are negative numbers */

pm_optParseOptions3(, (char **)argv, opt, sizeof(opt), 0);
/* Uses and sets argc, argv, and some of *cmdlineP and others. */


if (renditionSpec) {
if (cmdlineP->rendition < 1)
pm_error("The -rendition value must be at least 1");
} else
cmdlineP->rendition = 1;

if (cmdlineP->transparent && cmdlineP->showhist)
pm_error("You can't specify -showhist with -transparent");

if (argc-1 < 1)
cmdlineP->inputFilespec = "-";
else {
cmdlineP->inputFilespec = argv[1];
if (argc-1 > 1)
pm_error("Too many arguments (%d).  The only non-option "
 "argument is the file name", argc-1);
}
free(option_def);
}



static xelval *
createGraymap(unsigned int const ncolors,
  xelval   const maxval) {
int i;
xelval *map;

MALLOCARRAY_NOFAIL(map, ncolors);
  

Bug#1007234: Test suite fails on all but amd64 arches

2022-03-25 Thread Mathieu Malaterre
For some reason I never got your answer. So I've subscribed to
`1007...@bugs.debian.org`

> I'm sure this is easy to diagnose for someone who can reproduce it.

I've followed the instructions from:
* https://wiki.debian.org/RISC-V#debootstrap

I have now a RISCV-64 arch on my amd64 machine.

Now:

$ dget -u 
http://deb.debian.org/debian/pool/main/n/netpbm-free/netpbm-free_10.97.00-1.dsc
$ cd netpbm*
$ debuild -B

So I have a complete built tree of netpbm. What should I do now for issue:

...

== palm-roundtrip.test ==
pamdepth: promoting from black and white to grayscale
palmtopnm: Invalid Palm image input.  Header says 30 bytes per row
after uncompressing from 8-bit Packbits, but we counted 4294967069
bytes in a row, before we stopped processing the row
pnmcolormap: making histogram...
pnmcolormap: Scanning image 0
pnmcolormap: 20314 colors so far
pnmcolormap: 20314 colors found
pnmcolormap: choosing 256 colors...
pnmremap: 256 colors found in colormap
palmtopnm: Invalid Palm image input.  Header says 228 bytes per row
after uncompressing from 8-bit Packbits, but we counted 4294967044
bytes in a row, before we stopped processing the row
palm-roundtrip.test: FAILURE
...

Thanks



Bug#1007234: Test suite fails on all but amd64 arches

2022-03-21 Thread Bryan Henderson
I haven't heard of this before.

I'm sure this is easy to diagnose for someone who can reproduce it.  I can't,
since I don't have access to a system other than AMD64.

I can tell from reading the code that what is happening is there is a
a negative number somewhere that there shouldn't be.  My best guess is that
the 2's complement arithmetic hack for interpreting the run-length-encoding
in the function 'readPackBitsRow16' in converter/other/pnmtopalm/palmtopnm.c
isn't doing what it's expected to do.  In particular, the line

  int const signedIncount = (signed char)incountByte

might be declaring a positive number, whereas it's supposed to be negative
(which means -signedIncount below is negative whereas it is expected to be
positive).

-- 
Bryan Henderson   San Jose, California



Bug#1007234: Test suite fails on all but amd64 arches

2022-03-21 Thread Mathieu Malaterre
Dear Bryan,

Could you comment on the buildds failures at:

* https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1007234

For example on ppc64el (little endian system):

* 
https://buildd.debian.org/status/fetch.php?pkg=netpbm-free=ppc64el=2%3A10.97.00-1=1647179729=0


[...]

== palm-roundtrip.test ==
pamdepth: promoting from black and white to grayscale
palmtopnm: Invalid Palm image input.  Header says 30 bytes per row
after uncompressing from 8-bit Packbits, but we counted 4294967069
bytes in a row, before we stopped processing the row
pnmcolormap: making histogram...
pnmcolormap: Scanning image 0
pnmcolormap: 20314 colors so far
pnmcolormap: 20314 colors found
pnmcolormap: choosing 256 colors...
pnmremap: 256 colors found in colormap
palmtopnm: Invalid Palm image input.  Header says 228 bytes per row
after uncompressing from 8-bit Packbits, but we counted 4294967044
bytes in a row, before we stopped processing the row
palm-roundtrip.test: FAILURE

== palm-roundtrip2.test ==
pnmremap: 231 colors found in colormap
palmtopnm: Invalid Palm image input.  Header says 228 bytes per row
after uncompressing from 8-bit Packbits, but we counted 4294967088
bytes in a row, before we stopped processing the row
palm-roundtrip2.test: FAILURE
[...]

Thanks !