Return-Path: <tiff-bounces@lists.maptools.org>
X-Original-To: info@awaresystems.be
Delivered-To: info@awaresystems.be
Received: from mx-s.b-one.net (mx-s.one.com [91.198.169.250])
	by mail9.b-one.net (Postfix) with ESMTP id A426740013C
	for <info@awaresystems.be>; Mon, 23 Aug 2010 17:10:37 +0200 (CEST)
Received: by mx-s.b-one.net (Postfix, from userid 106)
	id 9754A4F942D6; Mon, 23 Aug 2010 17:10:37 +0200 (CEST)
X-Virus-Scanned: by one.com
X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "MIME-Version"
X-Spam-Flag: NO
X-Spam-Score: 0.001
X-Spam-Level: 
X-Spam-Status: No, score=0.001 tagged_above=0 required=4
 tests=[HTML_MESSAGE=0.001]
X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4
Received: from lists.maptools.org (lists.maptools.org [65.39.174.144]) by
 mx-s.b-one.net (Postfix) with ESMTP id 8F4D34F942D5 for
 <info@awaresystems.be>; Mon, 23 Aug 2010 17:10:36 +0200 (CEST)
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by
 lists.maptools.org (Postfix) with ESMTP id 91C4E1D184BEE; Mon, 23 Aug 2010
 10:09:53 -0500 (EST)
Received: from mail-bw0-f44.google.com (mail-bw0-f44.google.com
 [209.85.214.44]) by lists.maptools.org (Postfix) with ESMTP id 91CEE1D184BEB
 for <tiff@lists.maptools.org>; Mon, 23 Aug 2010 10:02:53 -0500 (EST)
Received: by bwz9 with SMTP id 9so4636954bwz.3 for <tiff@lists.maptools.org>;
 Mon, 23 Aug 2010 08:02:52 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.204.179.19 with SMTP id bo19mr3478222bkb.209.1282575772495;
 Mon, 23 Aug 2010 08:02:52 -0700 (PDT)
Received: by 10.204.178.207 with HTTP; Mon, 23 Aug 2010 08:02:52 -0700 (PDT)
In-Reply-To: <4C727AB1.20109@sidefx.com>
References: <AANLkTinJ7Lj9CYfCeLV41mQ75Vc3cem6+X+hQ-XymvMB@mail.gmail.com>
 <4C727AB1.20109@sidefx.com>
Date: Mon, 23 Aug 2010 11:02:52 -0400
Message-ID: <AANLkTikv8zFwOWmRXPVNo8Oi=MYb7OpUkqrU_yzchjTp@mail.gmail.com>
From: Rajat Varma <varma.rajat@gmail.com>
To: tiff@lists.maptools.org
Subject: Re: [Tiff] memory error
X-BeenThere: tiff@lists.maptools.org
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: TIFF and libtiff discussion <tiff.lists.maptools.org>
List-Unsubscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
 <mailto:tiff-request@lists.maptools.org?subject=unsubscribe>
List-Archive: <http://lists.maptools.org/mailman/private/tiff>
List-Post: <mailto:tiff@lists.maptools.org>
List-Help: <mailto:tiff-request@lists.maptools.org?subject=help>
List-Subscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
 <mailto:tiff-request@lists.maptools.org?subject=subscribe>
Content-Type: multipart/mixed; boundary="===============0814462306=="
Mime-version: 1.0
Sender: tiff-bounces@lists.maptools.org
Errors-To: tiff-bounces@lists.maptools.org

--===============0814462306==
Content-Type: multipart/alternative; boundary=001636c5a93c5131c5048e7ef189

--001636c5a93c5131c5048e7ef189
Content-Type: text/plain; charset=ISO-8859-1

Dear Edward,

Thanks for your response. All my declarations are according to the man page
that you send me. Here is my sample code testwrite.c, from which I generated
the exec testwrite.

#include <stdio.h>
#include <tiffio.h>
#include <stdarg.h>
#include <stdlib.h>

main(argc, argv)
int argc;
char *argv[];

{
                TIFF *in;
                toff_t* bc;
                uint32 rowspstrip,numrows,numcols;
                uint16 bits;

                in = TIFFOpen(argv[1],"r");

                TIFFGetField(in, TIFFTAG_STRIPBYTECOUNTS, &bc);
                TIFFGetField(in,TIFFTAG_IMAGELENGTH,&numrows);
                TIFFGetField(in,TIFFTAG_IMAGEWIDTH,&numcols);
                TIFFGetField(in,TIFFTAG_ROWSPERSTRIP,&rowspstrip);
                TIFFGetField(in,TIFFTAG_BITSPERSAMPLE,&bits);

                TIFFClose(in);

}

and I am getting two kind of errors in valgrind. First TIFFOpen is returning
a NULL pointer and second issue is with TIFFGetField. Please see below.

==5751== Syscall param open(filename) points to unaddressable byte(s)
==5751==    at 0x41659BD: open64 (in /lib/libc-2.10.1.so)
==5751==    by 0x4078D6C: TIFFOpen (tif_unix.c:171)
==5751==    by 0x8048594: main (in
/home/rajat/Desktop/spots_program/testwrite)
==5751==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==5751==
==5751==
==5751== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- n
TIFFOpen: (null): Cannot open.
==5751== Invalid read of size 4
==5751==    at 0x404CCEB: TIFFFindFieldInfo (tif_dirinfo.c:753)
==5751==    by 0x404A843: TIFFVGetField (tif_dir.c:971)
==5751==    by 0x404B33A: TIFFGetField (tif_dir.c:957)
==5751==    by 0x80485B4: main (in
/home/rajat/Desktop/spots_program/testwrite)
==5751==  Address 0x284 is not stack'd, malloc'd or (recently) free'd
==5751==
==5751==
==5751== ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- n
==5751==
==5751== Process terminating with default action of signal 11 (SIGSEGV)
==5751==  Access not within mapped region at address 0x284
==5751==    at 0x404CCEB: TIFFFindFieldInfo (tif_dirinfo.c:753)
==5751==    by 0x404A843: TIFFVGetField (tif_dir.c:971)
==5751==    by 0x404B33A: TIFFGetField (tif_dir.c:957)
==5751==    by 0x80485B4: main (in
/home/rajat/Desktop/spots_program/testwrite)
==5751==  If you believe this happened as a result of a stack
==5751==  overflow in your program's main thread (unlikely but
==5751==  possible), you can try to increase the size of the
==5751==  main thread stack using the --main-stacksize= flag.
==5751==  The main thread stack size used in this run was 8388608.

Any insights will be highly appreciated.

thanks

rajat

On Mon, Aug 23, 2010 at 9:42 AM, Edward Lam <edward@sidefx.com> wrote:

> On 8/22/2010 9:26 AM, Rajat Varma wrote:
> > ==25472== Invalid read of size 4
> > ==25472==    at 0x404CCEB: TIFFFindFieldInfo (tif_dirinfo.c:753)
> > ==25472==    by 0x404A843: TIFFVGetField (tif_dir.c:971)
> > ==25472==    by 0x404B33A: TIFFGetField (tif_dir.c:957)
> > ==25472==    by 0x8048B3D: main (in
> > /home/rajat/Desktop/spots_program/spotsprogram)
> > ==25472==  Address 0x284 is not stack'd, malloc'd or (recently) free'd
> >
> > Could anyone have an insight as to what kind of problems in the code
> > could give rise to such errors?
>
> My knee jerk reaction is that you're giving TIFFGetField() invalid
> return memory. Make sure you're giving it pointers to the right
> types/sizes according to your field:
>
> http://libtiff.maptools.org/man/TIFFGetField.3tiff.html
>
> Regards,
> -Edward
> _______________________________________________
> Tiff mailing list: Tiff@lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/tiff
> http://www.remotesensing.org/libtiff/
>

--001636c5a93c5131c5048e7ef189
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Dear Edward,<br><br>Thanks for your response. All my declarations are accor=
ding to the man page that you send me. Here is my sample code testwrite.c, =
from which I generated the exec testwrite.<br><br>#include &lt;stdio.h&gt;<=
br>
#include &lt;tiffio.h&gt;<br>#include &lt;stdarg.h&gt;<br>#include &lt;stdl=
ib.h&gt;<br><br>main(argc, argv)<br>int argc;<br>char *argv[];<br><br>{<br>=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 TIFF *in;<br>=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 toff_t* bc;<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0 uint32 rowspstrip,numrows,numcols;<br>
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 uint16 bits;<br><br>=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 in =3D TIFFOpen(argv[1],&quot;r&quot;)=
;<br><br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 TIFFGetField(in, TIF=
FTAG_STRIPBYTECOUNTS, &amp;bc);<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0 TIFFGetField(in,TIFFTAG_IMAGELENGTH,&amp;numrows);<br>
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 TIFFGetField(in,TIFFTAG_IMAGE=
WIDTH,&amp;numcols);<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 TIFFG=
etField(in,TIFFTAG_ROWSPERSTRIP,&amp;rowspstrip);<br>=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0 TIFFGetField(in,TIFFTAG_BITSPERSAMPLE,&amp;bits);<=
br><br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 TIFFClose(in);<br>
<br>}<br><br>and I am getting two kind of errors in valgrind. First TIFFOpe=
n is returning a NULL pointer and second issue is with TIFFGetField. Please=
 see below.<br><br>=3D=3D5751=3D=3D Syscall param open(filename) points to =
unaddressable byte(s)<br>
=3D=3D5751=3D=3D=A0=A0=A0 at 0x41659BD: open64 (in /lib/<a href=3D"http://l=
ibc-2.10.1.so">libc-2.10.1.so</a>)<br>=3D=3D5751=3D=3D=A0=A0=A0 by 0x4078D6=
C: TIFFOpen (tif_unix.c:171)<br>=3D=3D5751=3D=3D=A0=A0=A0 by 0x8048594: mai=
n (in /home/rajat/Desktop/spots_program/testwrite)<br>
=3D=3D5751=3D=3D=A0 Address 0x0 is not stack&#39;d, malloc&#39;d or (recent=
ly) free&#39;d<br>=3D=3D5751=3D=3D<br>=3D=3D5751=3D=3D<br>=3D=3D5751=3D=3D =
---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- n<br>TIFFOpen: (nul=
l): Cannot open.<br>=3D=3D5751=3D=3D Invalid read of size 4<br>
=3D=3D5751=3D=3D=A0=A0=A0 at 0x404CCEB: TIFFFindFieldInfo (tif_dirinfo.c:75=
3)<br>=3D=3D5751=3D=3D=A0=A0=A0 by 0x404A843: TIFFVGetField (tif_dir.c:971)=
<br>=3D=3D5751=3D=3D=A0=A0=A0 by 0x404B33A: TIFFGetField (tif_dir.c:957)<br=
>=3D=3D5751=3D=3D=A0=A0=A0 by 0x80485B4: main (in /home/rajat/Desktop/spots=
_program/testwrite)<br>
=3D=3D5751=3D=3D=A0 Address 0x284 is not stack&#39;d, malloc&#39;d or (rece=
ntly) free&#39;d<br>=3D=3D5751=3D=3D<br>=3D=3D5751=3D=3D<br>=3D=3D5751=3D=
=3D ---- Attach to debugger ? --- [Return/N/n/Y/y/C/c] ---- n<br>=3D=3D5751=
=3D=3D<br>=3D=3D5751=3D=3D Process terminating with default action of signa=
l 11 (SIGSEGV)<br>
=3D=3D5751=3D=3D=A0 Access not within mapped region at address 0x284<br>=3D=
=3D5751=3D=3D=A0=A0=A0 at 0x404CCEB: TIFFFindFieldInfo (tif_dirinfo.c:753)<=
br>=3D=3D5751=3D=3D=A0=A0=A0 by 0x404A843: TIFFVGetField (tif_dir.c:971)<br=
>=3D=3D5751=3D=3D=A0=A0=A0 by 0x404B33A: TIFFGetField (tif_dir.c:957)<br>
=3D=3D5751=3D=3D=A0=A0=A0 by 0x80485B4: main (in /home/rajat/Desktop/spots_=
program/testwrite)<br>=3D=3D5751=3D=3D=A0 If you believe this happened as a=
 result of a stack<br>=3D=3D5751=3D=3D=A0 overflow in your program&#39;s ma=
in thread (unlikely but<br>=3D=3D5751=3D=3D=A0 possible), you can try to in=
crease the size of the<br>
=3D=3D5751=3D=3D=A0 main thread stack using the --main-stacksize=3D flag.<b=
r>=3D=3D5751=3D=3D=A0 The main thread stack size used in this run was 83886=
08.<br><br>Any insights will be highly appreciated.<br><br>thanks<br><br>ra=
jat<br><br><div class=3D"gmail_quote">
On Mon, Aug 23, 2010 at 9:42 AM, Edward Lam <span dir=3D"ltr">&lt;<a href=
=3D"mailto:edward@sidefx.com">edward@sidefx.com</a>&gt;</span> wrote:<br><b=
lockquote class=3D"gmail_quote" style=3D"border-left: 1px solid rgb(204, 20=
4, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class=3D"im">On 8/22/2010 9:26 AM, Rajat Varma wrote:<br>
&gt; =3D=3D25472=3D=3D Invalid read of size 4<br>
&gt; =3D=3D25472=3D=3D =A0 =A0at 0x404CCEB: TIFFFindFieldInfo (tif_dirinfo.=
c:753)<br>
&gt; =3D=3D25472=3D=3D =A0 =A0by 0x404A843: TIFFVGetField (tif_dir.c:971)<b=
r>
&gt; =3D=3D25472=3D=3D =A0 =A0by 0x404B33A: TIFFGetField (tif_dir.c:957)<br=
>
&gt; =3D=3D25472=3D=3D =A0 =A0by 0x8048B3D: main (in<br>
&gt; /home/rajat/Desktop/spots_program/spotsprogram)<br>
&gt; =3D=3D25472=3D=3D =A0Address 0x284 is not stack&#39;d, malloc&#39;d or=
 (recently) free&#39;d<br>
&gt;<br>
&gt; Could anyone have an insight as to what kind of problems in the code<b=
r>
&gt; could give rise to such errors?<br>
<br>
</div>My knee jerk reaction is that you&#39;re giving TIFFGetField() invali=
d<br>
return memory. Make sure you&#39;re giving it pointers to the right<br>
types/sizes according to your field:<br>
<br>
<a href=3D"http://libtiff.maptools.org/man/TIFFGetField.3tiff.html" target=
=3D"_blank">http://libtiff.maptools.org/man/TIFFGetField.3tiff.html</a><br>
<br>
Regards,<br>
<font color=3D"#888888">-Edward<br>
</font><div><div></div><div class=3D"h5">__________________________________=
_____________<br>
Tiff mailing list: <a href=3D"mailto:Tiff@lists.maptools.org">Tiff@lists.ma=
ptools.org</a><br>
<a href=3D"http://lists.maptools.org/mailman/listinfo/tiff" target=3D"_blan=
k">http://lists.maptools.org/mailman/listinfo/tiff</a><br>
<a href=3D"http://www.remotesensing.org/libtiff/" target=3D"_blank">http://=
www.remotesensing.org/libtiff/</a><br>
</div></div></blockquote></div><br>

--001636c5a93c5131c5048e7ef189--

--===============0814462306==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
--===============0814462306==--
