Bug 688222

Summary: Another crash in igc_reloc_struct_ptr
Product: Ghostscript Reporter: Igor Melichev <igor.melichev>
Component: GeneralAssignee: Igor Melichev <igor.melichev>
Status: NOTIFIED FIXED    
Severity: normal    
Priority: P3    
Version: 0.00   
Hardware: PC   
OS: Windows XP   
Customer: Word Size: ---
Attachments: valgrind log

Description Igor Melichev 2005-07-20 09:03:35 UTC
Crash in igc.c ln 1272 in igc_reloc_struct_ptr called from show_enum_reloc_ptrs.
Command line :

gswin32c.exe -r72 -dNOPAUSE -dNOOUTERSAVE -sDEVICE=ppmraw -sOutputFile=z:\t2
\hdr.ppm z:\t2\hdr.ps -c quit  1>>hdr-1.log 2>>hdr-2.log

Will attach the test file.
Comment 1 Igor Melichev 2005-07-20 09:04:59 UTC
Created attachment 1549 [details]
hdr.ps

The test file is generated from comparefiles/japan.ps with ps2write.
Comment 2 Igor Melichev 2005-07-20 09:08:36 UTC
-Z$@? doesn't detect an error.
Comment 3 Dan Coby 2005-07-20 11:00:22 UTC
I am unable to reproduce this problem.

My command line:

bin/gswin32c.exe -r72 -dNOPAUSE -dNOOUTERSAVE -sDEVICE=ppmraw -sOutputFile=xx
.pnm ../test_files/688222.ps -c quit 1>>log 2>>log2

I am uaing current CVS head, WinXP, and the MSVC .NET 2003 compiler
Comment 4 Igor Melichev 2005-07-20 11:24:41 UTC
My compiler is Microsoft Visual C++ 2005   55603-000-0000016-00642
Comment 5 Igor Melichev 2005-07-20 13:14:18 UTC
Well, I spent an hour for finding a reason one one my copy of Ghostscript 
crash, and another one doesn't. After many attempts I erased obj and bin 
directories and built them anew in both copies. Still one runs, and another one 
crash. Interesting that obj directories got a different size.

Then I noticed that the directory names have different length, so the commnds 
look like this :
..\..\gs-hd\bin\gswin32c.exe -IF:/AFPL/gs-hd/lib;f:\afpl\fonts -r72 -dNOPAUSE -
dNOOUTERSAVE -sDEVICE=ppmraw -sOutputFile=cur.ppm attachment.ps -c quit
..\..\gs-hdr\bin\gswin32c.exe -IF:/AFPL/gs-hdr/lib;f:\afpl\fonts -r72 -
dNOPAUSE -dNOOUTERSAVE -sDEVICE=ppmraw -sOutputFile=cur.ppm attachment.ps -c 
quit

When I create a copy of the first directory with the name GS-HDE, it crashes, 
rather with GS_HD it doesn't. Also creating a copy of the second one with the 
name GS_HE, it doesn't crash, rather than gs_HDR does.

Thus the effect strongly depends on the directory name length, maybe due to it 
is used in the -I command like option.

I don't think that you guys can reproduce this, so I'll stop any other work to 
exclude variations of environment untill I find the reason for the problem.

Comment 6 Alex Cherepanov 2005-07-20 19:40:15 UTC
Created attachment 1551 [details]
valgrind log

This is a Valgrind log for the test cass on my GNU+Linux box.
I hope it helps. It looks like there are several errors in the GC code.
The errors about memory and string functions are mostly harmless.
The error about the "Use of uninitialised value of size 4"
will be addressed separately. I think we need to test GS under valgrind
during regression testing, at least occasionaly.
Comment 7 Igor Melichev 2005-07-20 23:54:40 UTC
I opened a new bug 688225 about the valgrind report. Please put related 
followups to there.
Comment 8 Igor Melichev 2005-07-21 00:36:28 UTC
The crash happens due to an attempt to relocate a pointer 
gs_show_enum::dev_cache2. There exist a single place where such structure is 
being allocated, and the field is immediately initialized. At the crash point 
the pointer points to an area with a good data (an image1 device), but the 
descriptor of the area is bad. Maybe it was prematurely released, or allocated 
in a wrong space, or its descriptor was damaged ?
Comment 9 Igor Melichev 2005-07-21 00:38:45 UTC
Running -Z? gives a crash in ialloc_validate_object regadring to that pointer. 
So I conclude that the pointer damage happens quite immediately before the 
garbager invocation.
Comment 10 Igor Melichev 2005-07-21 00:48:47 UTC
Well, the instance of gs_show_enum is allocated in global memory, and 
dev_cache2 points to a local memory. It happens due to gs_show_enum is being 
allocated in the current memory space, rather than cache devices do in the 
space of the graphic state.

Recently we fixed a similar problem with gs_image_enum. So now we know what to 
do.
Comment 11 Igor Melichev 2005-07-21 02:55:04 UTC
See also Bug 688227.
Comment 12 Igor Melichev 2005-07-21 02:55:37 UTC
Patch to HEAD :
http://ghostscript.com/pipermail/gs-cvs/2005-July/005615.html