tasen / leptonica

Automatically exported from code.google.com/p/leptonica
0 stars 0 forks source link

Activating ADD_LEPTONICA_SUBDIR causes opening files from /tmp to fail #110

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. place image int /tmp/image.jpg
2. tesseract /tmp/image.jpg ocrresult -psm 3

What is the expected output? What do you see instead?
Tesseract should run but instead quits with could not open file. strace shows 
the input path gets modified.

What version of the product are you using? On what operating system?
gentoo linux. leptonica-1.72-r1

Please provide any additional information below.
This issue is caused by activating ADD_LEPTONICA_SUBDIR. in src/utils.c 
genPathname() then modifies paths in /tmp. This should not happen for user 
given paths.
I looked into it and did not find a quick solution. This issue relates to many 
functions in which it should differentiate between user given paths and ones to 
modify.

Original issue reported on code.google.com by goo...@doofy.speciesm.net on 29 May 2015 at 12:20

GoogleCodeExporter commented 8 years ago
Hold off on this one, Dan, I need to look closer at what ADD_LEPTONICA_SUBDIR 
actually does.

Original comment by JerseyChewi@gmail.com on 29 May 2015 at 1:12

GoogleCodeExporter commented 8 years ago
For now, I have simply stopped using ADD_LEPTONICA_SUBDIR in the Gentoo 
package. When I enabled it, I thought it only affected the test suite. A quick 
glance at utils.c only confused me further.

Up till now, I've tried to limit my comments to the build system since I really 
have no expert knowledge of image manipulation but I have to say that poorly 
reinventing the wheel with so many helper functions is pretty bad practise. I 
think Leptonica could really benefit from a dependency on glib, which would 
(probably, admittedly I don't know it well) give you well-maintained 
cross-platform replacements for almost all the functions in utils.c.

At the very least, Leptonica should respect the TMPDIR environment variable as 
this would deal with one of the worst aspects of the file handling. It already 
respects TEMP, the Windows equivalent.

Original comment by JerseyChewi@gmail.com on 4 Jun 2015 at 11:14

GoogleCodeExporter commented 8 years ago
Ouch.

James, as you know, I've gone through 3 iterations of this temp directory stuff.

I strongly resisted the idea of rewriting the path -- it seems like a bad idea 
because it must confuse users who say to write to path P and it writes to path 
Q.  It was also complicated, and complicated stuff is also generally a bad idea 
if there are much easier ways to do it.

However, I was assured that it was important on windows that the tests not 
write to /tmp.  Faced with the choice of rewriting over 100 tests or providing 
the option of automatically writing to <temp>/leptonica/, I reluctantly 
acquiesced.

Perhaps it was the wrong decision, and the correct decision would have been to 
either ignore the suggestions or rewrite the tests.

As it is, we seem to have several different sets of users.  The windows and 
cygwin user gurus demanded rewriting the tmp path.  I couldn't imagine unix 
users wanting to rewrite the path, so I provided the simpler, more transparent 
approach for everyone else.  I have to ask you -- gentoo is linux; why would 
you want to write to a subdir of tmp on linux?

I remain willing to rip out all this LEPTONICA SUBDIR stuff, and rewriting the 
tests may not be as hard as I had originally thought, especially if I make the 
regutils.c functions do some of the work.

Original comment by dan.bloo...@gmail.com on 5 Jun 2015 at 1:44

GoogleCodeExporter commented 8 years ago
This rewrite option will be removed in 1.73.

Original comment by dan.bloo...@gmail.com on 22 Aug 2015 at 10:57

GoogleCodeExporter commented 8 years ago
Hi Dan. Sorry that the earlier e-mail discussion kinda petered out. Gentoo work 
has been pretty heavy-going. Still, I think it got us all on the same page and 
removing this seems like the way to go. I would be grateful if you could send a 
new tarball for review and I will patch it to respect TMPDIR if you haven't 
done so already.

Original comment by JerseyChewi@gmail.com on 23 Aug 2015 at 8:39