On Mon, Jul 14, 2008 at 01:23:00PM +0200, Sven Joachim wrote:
> forwarded 489733 https://bugzilla.mozilla.org/show_bug.cgi?id=278738
> thanks
>
> On 2008-07-14 13:18 +0200, Mike Hommey wrote:
>
> > On Mon, Jul 14, 2008 at 12:28:51PM +0200, Sven Joachim wrote:
> >> But it will not trigger the bug. Instead I have found a way to
> >> reproduce it:
> >>
> >> --8<---------------cut here---------------start------------->8---
> >> # create scratch directory
> >> mkdir /tmp/scratch
> >> cd /tmp/scratch
> >> # create a bunch of files for the listing
> >> touch $(seq 500)
> >> # create a big file
> >> dd if=/dev/zero of=sparse-file bs=1 count=0 seek=2G
> >> --8<---------------cut here---------------end--------------->8---
> >>
> >> => The listing of /tmp/scratch in the browsers is truncated.
> >>
> >> This will very likely not be reproducible under amd64, so you should get
> >> yourself an i386 chroot for it. In the original directory I have a 4G
> >> DVD image which triggered the problem.
> >
> > It doesn't display anything here, though I didn't do the touch $(seq
> > 500)...
>
> Probably it doesn't display anything _because_ you didn't run the touch
> command. Meanwhile I found an upstream bug at
> https://bugzilla.mozilla.org/show_bug.cgi?id=278738 that states
> compiling with -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 might work.
I doubt that, because of some bad casting.
Can you try the attached patch?
Mike
diff --git a/xpcom/io/nsLocalFileUnix.cpp b/xpcom/io/nsLocalFileUnix.cpp
index 99f52a6..d798ff7 100644
--- a/xpcom/io/nsLocalFileUnix.cpp
+++ b/xpcom/io/nsLocalFileUnix.cpp
@@ -280,12 +280,21 @@ nsLocalFile::nsLocalFileConstructor(nsISupports *outer,
nsresult
nsLocalFile::FillStatCache() {
+#ifdef HAVE_STAT64
+ if (stat64(mPath.get(), &mCachedStat) == -1) {
+ // try lstat it may be a symlink
+ if (lstat64(mPath.get(), &mCachedStat) == -1) {
+ return NSRESULT_FOR_ERRNO();
+ }
+ }
+#else
if (stat(mPath.get(), &mCachedStat) == -1) {
// try lstat it may be a symlink
if (lstat(mPath.get(), &mCachedStat) == -1) {
return NSRESULT_FOR_ERRNO();
}
}
+#endif
mHaveCachedStat = PR_TRUE;
return NS_OK;
}
@@ -1109,9 +1118,12 @@ nsLocalFile::GetFileSize(PRInt64 *aFileSize)
}
#endif
- /* XXX autoconf for and use stat64 if available */
if (!S_ISDIR(mCachedStat.st_mode)) {
+#ifdef HAVE_STAT64
+ *aFileSize = mCachedStat.st_size;
+#endif
LL_UI2L(*aFileSize, (PRUint32)mCachedStat.st_size);
+#endif
}
return NS_OK;
}
@@ -1139,8 +1151,11 @@ nsLocalFile::GetFileSizeOfLink(PRInt64 *aFileSize)
struct stat sbuf;
if (lstat(mPath.get(), &sbuf) == -1)
return NSRESULT_FOR_ERRNO();
- /* XXX autoconf for and use lstat64 if available */
+#ifdef HAVE_STAT64
+ *aFileSize = sbuf.st_size;
+#endif
LL_UI2L(*aFileSize, (PRUint32)sbuf.st_size);
+#endif
return NS_OK;
}
diff --git a/xpcom/io/nsLocalFileUnix.h b/xpcom/io/nsLocalFileUnix.h
index 9203b33..c51f2d9 100644
--- a/xpcom/io/nsLocalFileUnix.h
+++ b/xpcom/io/nsLocalFileUnix.h
@@ -113,7 +113,11 @@ private:
~nsLocalFile() {}
protected:
+#ifdef HAVE_STAT64
+ struct stat64 mCachedStat;
+#else
struct stat mCachedStat;
+#endif
nsCString mPath;
PRPackedBool mHaveCachedStat;