English 中文(简体)
Redhat AS 4 seg fault calling magic_buffer using Java 1.6
原标题:

I have a java class that calls a C++ class via a JNI C++ class to access the file command functionality provided by libmagic.so.

  • The C++ class compiles and run fine as a C++ main()

-It works fine on RHEL 5 running java 1.5 and 1.6;

-it works fine on RHEL 4 running java 1.5

-it throws a seg fault 26234 on the RHEL 4 with java 1.6

The seg fault:

  1. Occurs at the call char* retptr = magic_buffer(cookie, bigbuf, 1000); No fault when char* retptr = “a nice safe character string”; is substituted. This is why I conclude that the seg fault occurs at this call.

  2. I use an alternative call, char* retptr = magic_file(cookie,”/usr/include/magic.h”); to debug buffer problems, as this call returns the same file type message requiring only the fully qualified path name of the file, rather than a buffer full of the file content. It also throws the seg fault on the RHEL4/java 1.6 test VM. Thus, I conclude the problem does not appear to be bad pointers or overflowing buffers in my code.

  3. magic_buffer is a call to libmagic.so. In the code previously, other successful calls to this lib are made. This call, however, involves the lib magic database /usr/share/file/magic.

  4. Compiling the C++ as an executable and running it on the problem machine works just fine.

Here s some conclusions:

A. There is JNI involvement, because of #4

B. Because of #1/#2, I don t believe it is a JNI implementation issue.

C. Because of #1, #2, and #4 I don t believe it is a c++ implementation issue.

Any suggestions or comments? (initially run on VMWare, now tested with no VM involvement)

问题回答

My first suggestion is to try and find a pure Java alternative. This page lists a number of alternatives. Apache Tika and JMimeMagic look promising.

My second suggestion is to use Process to run the file command in a separate process and scrape the information you need from the command s standard output. This may have (ahem) performance issues if you need to do this hundreds of times a second, but for occasional use it should be fine.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签