[sldev] OpenJPEG MAX_PATH issue
David Fries
david at fries.net
Sat Jan 20 14:43:49 PST 2007
Give it a read through and let me know what you think?
Summary: MAX_PATH or PATH_MAX, and how to make everything see the same
size? My suggestion? See if OpenJPEG can just do,
#define OPJ_PATH_LEN 4096
and use that in their data structures. (patch attached against
openjpeg_v1_1.tar.gz)
I was having a problem that was causing the open source version of the
Second Life viewer to crash with the OpenJPEG library. I tracked it
down to openjpeg.h and the opj_cparameters structure. There are three
character arrays in that data structure that are of size MAX_PATH.
openjpeg.h contains a check to define MAX_PATH to 260 if it isn't
defined. When I compiled OpenJPEG it wasn't defined. Second Life on
the other hand defines it, to some other size, so that
LLImageJ2COJ::encodeImpl creates a structure that is bigger in size
and passes a pointer for OpenJPEG to initialize. OpenJPEG's library
has a different and smaller layout for the data variables in that
structure. Thus encodeImpl reads garbage when it goes to process what
OpenJPEG initialized and crashes.
I started looking through the header files on my system to see what
has PATH_MAX listed in it, no standard system libraries define it or
use it. Here are the results.
/usr/include/boost/regex/v4/fileiter.hpp
boost regular expression library, defines MAX_PATH to 256 if
it isn't already defined.
/usr/include/lcms.h
Color management library, defines MAX_PATH to 256 without even
checking to see if it was previously defined.
/usr/include/X11/Xos.h
X11 core library, doesn't even check just
#define MAX_PATH _POSIX_PATH_MAX
(and then doesn't even use it).
On the other hand there are 20 files that use PATH_MAX and it is
mentioned in various man pages.
/usr/include/limits.h is the place to pick up PATH_MAX
/usr/include/linux/limits.h (which shouldn't be included directly)
#define PATH_MAX 4096 /* # chars in a path name including nul */
Then there is one that will change the size of PATH_MAX on windows.
/usr/include/X11/Xwindows.h
#if defined(WIN32) && (!defined(PATH_MAX) || PATH_MAX < 1024)
#undef PATH_MAX
#define PATH_MAX 1024
#endif
Looking around there are a few different sizes for PATH_MAX
/usr/include/linux/limits.h:#define PATH_MAX 4096
/usr/include/X11/Xwindows.h:#define PATH_MAX 1024
/usr/include/X11/InitialI.h:#define PATH_MAX 512
I think this is telling,
/usr/include/postgresql/pg_config_manual.h
/*
* MAXPGPATH: standard size of a pathname buffer in PostgreSQL (hence,
* maximum usable pathname length is one less).
*
* We'd use a standard system header symbol for this, if there weren't
* so many to choose from: MAXPATHLEN, MAX_PATH, PATH_MAX are all
* defined by different "standards", and often have different values
* on the same platform! So we just punt and use a reasonably
* generous setting here.
*/
#define MAXPGPATH 1024
--
David Fries <david at fries.net>
http://fries.net/~david/ (PGP encryption key available)
-------------- next part --------------
--- ./OpenJPEG/libopenjpeg/openjpeg.h 2006-12-04 08:59:33.000000000 -0600
+++ ./DebugOpenJPEG/libopenjpeg/openjpeg.h 2007-01-20 16:14:06.000000000 -0600
@@ -89,9 +89,8 @@
==========================================================
*/
-#ifndef MAX_PATH
-#define MAX_PATH 260 /**< Maximum allowed size for filenames */
-#endif /* MAX_PATH */
+
+#define OPG_PATH_LEN 4096
#define J2K_MAXRLVLS 33 /**< Number of maximum resolution level authorized */
#define J2K_MAXBANDS (3*J2K_MAXRLVLS-2) /**< Number of maximum sub-band linked to number of resolution level */
@@ -255,13 +254,13 @@
/**@name command line encoder parameters (not used inside the library) */
/*@{*/
/** input file name */
- char infile[MAX_PATH];
+ char infile[OPG_PATH_LEN];
/** output file name */
- char outfile[MAX_PATH];
+ char outfile[OPG_PATH_LEN];
/** creation of an index file, default to 0 (false) */
int index_on;
/** index file name */
- char index[MAX_PATH];
+ char index[OPG_PATH_LEN];
/** subimage encoding: origin image offset in x direction */
int image_offset_x0;
/** subimage encoding: origin image offset in y direction */
@@ -335,9 +334,9 @@
/**@name command line encoder parameters (not used inside the library) */
/*@{*/
/** input file name */
- char infile[MAX_PATH];
+ char infile[OPG_PATH_LEN];
/** output file name */
- char outfile[MAX_PATH];
+ char outfile[OPG_PATH_LEN];
/** input file format 0: J2K, 1: JP2, 2: JPT */
int decod_format;
/** output file format 0: PGX, 1: PxM, 2: BMP */
More information about the SLDev
mailing list