This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
natFileChannelPosix: throw if region is not mapped
- From: Andrew Haley <aph at redhat dot com>
- To: classpath-patches at gnu dot org, java-patches at gcc dot gnu dot org
- Date: Wed, 1 Nov 2006 16:59:58 +0000
- Subject: natFileChannelPosix: throw if region is not mapped
According to the spec, this case is undefined. However, if we do
attempt to read the data in a nonexistent region we'll get a bus
error. It makes sense to throw a helpful exception, and it seems that
at least one Java program relies on this behaviour.
This isn't a complete solution. At some point we'll need to catch the
bus error and do something appropriate.
Andrew.
2006-11-01 Andrew Haley <aph@redhat.com>
* gnu/java/nio/channels/natFileChannelPosix.cc (mapImpl): Throw
IOException if requested region is not completely contained within
file.
Index: gnu/java/nio/channels/natFileChannelPosix.cc
===================================================================
--- gnu/java/nio/channels/natFileChannelPosix.cc (revision 118387)
+++ gnu/java/nio/channels/natFileChannelPosix.cc (working copy)
@@ -513,6 +513,17 @@
throw new IOException (JvNewStringLatin1 (strerror (errno)));
buf->implPtr = reinterpret_cast<RawData*> (ptr);
buf->implLen = size+align;
+
+ struct stat st;
+
+ if (fstat (fd, &st))
+ throw new IOException (JvNewStringLatin1 (strerror (errno)));
+
+ if (size+position > st.st_size)
+ throw new IOException (JvNewStringLatin1
+ ("mmap: requested region not completely "
+ "contained within file\n"));
+
return buf;
#else
throw new IOException (JvNewStringUTF ("mmap not implemented"));