[evolution-patches] CamelSeekableSubstream prob



It looks like the seekable-substream type is being used to wrap steams
that are already seekable (like the memory stream).

If it does, it often upgrades the position member by adding (+=) the
amount of bytes that where written and read. If the underlying one also
does this (with the same integer), then the offset will be wrong.

I'm trying a bit with this patch, I'm not seeing a problem that I had
before, anymore.

I've also seen extremely huge values for the offset on ARM archs. Is it
possible that something is causing an overflow here? I noticed that none
of the stream-types initialise that position value to for example zero.
Why not? Maybe initialise it to -1 and report an error of an unset
stream is being read? Or use an unsigned field and initialise it to zero
(keeping a flag about the stream-set situation)?

hrmbl..


-- 
Philip Van Hoof, software developer
home: me at pvanhoof dot be 
gnome: pvanhoof at gnome dot org 
http://www.pvanhoof.be/blog



Index: camel-seekable-substream.c
===================================================================
--- camel-seekable-substream.c	(revision 1181)
+++ camel-seekable-substream.c	(working copy)
@@ -74,6 +74,14 @@
 }
 
 
+static void
+camel_seekable_substream_init (CamelObject *object)
+{
+	CamelSeekableStream *seekable_stream = CAMEL_SEEKABLE_STREAM (object);
+
+	seekable_stream->position = 0;
+}
+
 CamelType
 camel_seekable_substream_get_type (void)
 {
@@ -85,7 +93,7 @@
 								     sizeof (CamelSeekableSubstreamClass),
 								     (CamelObjectClassInitFunc) camel_seekable_substream_class_init,
 								     NULL,
-								     NULL,
+								     (CamelObjectInitFunc) camel_seekable_substream_init,
 								     (CamelObjectFinalizeFunc) camel_seekable_substream_finalize);
 	}
 
@@ -149,6 +157,7 @@
 	CamelSeekableStream *seekable_stream = CAMEL_SEEKABLE_STREAM (stream);
 	CamelSeekableSubstream *seekable_substream = CAMEL_SEEKABLE_SUBSTREAM (stream);
 	ssize_t v;
+	off_t orig;
 
 	if (n == 0)
 		return 0;
@@ -170,11 +179,15 @@
 		return 0;
 	}
 
+	orig = seekable_stream->position;
+
 	v = camel_stream_read (CAMEL_STREAM (parent), buffer, n);
 
 	/* ignore <0 - it's an error, let the caller deal */
-	if (v > 0)
-		seekable_stream->position += v;
+	if (v > 0) {
+		orig += v;
+		seekable_stream->position = orig;
+	}
 
 	return v;
 }
@@ -186,6 +199,7 @@
 	CamelSeekableStream *seekable_stream = CAMEL_SEEKABLE_STREAM(stream);
 	CamelSeekableSubstream *seekable_substream = CAMEL_SEEKABLE_SUBSTREAM(stream);
 	ssize_t v;
+	off_t orig;
 
 	if (n == 0)
 		return 0;
@@ -207,11 +221,15 @@
 		return 0;
 	}
 
+	orig = seekable_stream->position;
+
 	v = camel_stream_write((CamelStream *)parent, buffer, n);
 
 	/* ignore <0 - it's an error, let the caller deal */
-	if (v > 0)
-		seekable_stream->position += v;
+	if (v > 0) {
+		orig += v;
+		seekable_stream->position = orig;
+	}
 
 	return v;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]