Return-Path: <tiff-bounces@lists.osgeo.org>
Received: from mailgate211.isp.belgacom.be ([195.238.22.43])
          by mailfep004.skynet.be
          (InterMail vM.8.04.03.28.4 201-2389-100-182-103-20180124)
          with ESMTP
          id <20201211183950.KKJF7411.mailfep004.skynet.be@mailgate211.isp.belgacom.be>
          for <chris.lindelaan@skynet.be>; Fri, 11 Dec 2020 19:39:50 +0100
Authentication-Results: mx201.skynet.be; dkim=none (message not signed) header.i=none; spf=None smtp.pra=tiff-bounces@lists.osgeo.org; spf=Pass smtp.mailfrom=tiff-bounces@lists.osgeo.org; spf=Pass smtp.helo=postmaster@lists.osgeo.org
Received-SPF: None (mx201.skynet.be: no sender authenticity
  information available from domain of
  tiff-bounces@lists.osgeo.org) identity=pra;
  client-ip=140.211.15.3; receiver=mx201.skynet.be;
  envelope-from="tiff-bounces@lists.osgeo.org";
  x-sender="tiff-bounces@lists.osgeo.org";
  x-conformance=sidf_compatible
Received-SPF: Pass (mx201.skynet.be: domain of
  tiff-bounces@lists.osgeo.org designates 140.211.15.3 as
  permitted sender) identity=mailfrom; client-ip=140.211.15.3;
  receiver=mx201.skynet.be;
  envelope-from="tiff-bounces@lists.osgeo.org";
  x-sender="tiff-bounces@lists.osgeo.org";
  x-conformance=sidf_compatible; x-record-type="v=spf1";
  x-record-text="v=spf1 mx a:mail.osgeo.org a:lists.osgeo.org
  a:mail.osgeo.osuosl.org a:tracsvn.osgeo.osuosl.org -all"
Received-SPF: Pass (mx201.skynet.be: domain of
  postmaster@lists.osgeo.org designates 140.211.15.3 as
  permitted sender) identity=helo; client-ip=140.211.15.3;
  receiver=mx201.skynet.be;
  envelope-from="tiff-bounces@lists.osgeo.org";
  x-sender="postmaster@lists.osgeo.org";
  x-conformance=sidf_compatible; x-record-type="v=spf1";
  x-record-text="v=spf1 mx a:mail.osgeo.org a:lists.osgeo.org
  a:mail.osgeo.osuosl.org a:tracsvn.osgeo.osuosl.org -all"
X-Ironport-Dmarc-Check-Result: validskip
IronPort-SDR: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VRNPrH5Miufp9Q16Pr7F85BbRXve1BYM9nmLTRMRqNZiTNr1tO?=
 =?us-ascii?q?hcx8POm6T6NDpZu4uIpY1GXpGScZ/BazIoKn+LUHbMAREATCK3OG2XnEFbnP?=
 =?us-ascii?q?yItzWUopU8tpnwic8OR7tcBxQ+EvIXDFggHcRXecsvGGl9yPjC0YhTth/c5F?=
 =?us-ascii?q?HLSc5Xv47KTKeXEa+3cXCCjqhCagdOy76rSOZbfoD9xUFmbUF32YrQHE+FF8?=
 =?us-ascii?q?xMrCMkZAgppk5A61B6T3YvwATicQyg5zkUD/H+zXtUwkNuJP8g8jvh+QJ9Pl?=
 =?us-ascii?q?3RuC45i1U8g/3hgCuNa3j2N6i9WsdRESW+5C1TetvrBg1yawO1h0ltMjzJEq?=
 =?us-ascii?q?lQg7VXfmdukAbAuJFLFK0UXehebRQX3/3Se+Qw3AEWtHC83UEer7iga9MqhE?=
 =?us-ascii?q?4wfJWrtX4Fxw9zcIt/O/nLPKQQhl1Azqvcuyap0qY22wATIAAK6mzacXwMuV?=
 =?us-ascii?q?cULf8hPCWl+apr8wPn+XMLcToJXvsu5PVx+U46feOb0iX71/hEME/5Pr6DNa?=
 =?us-ascii?q?qSoHbG08mTTV43kEQTik5e+f5xy8hrNkOQUwp2kOmhUi8RPM+HEjl7KtJI/S?=
 =?us-ascii?q?GMLyKPqvnWh5VuMIi6UOfyQr3W7ftGsgefBA8sWr80wIEBE52riR6KKcb8MK?=
 =?us-ascii?q?VDzg4i6QOtI0+KXq0QKUC71QwfqsT696dZmIxUJzUTG2J4aHrl4rfMuhRsh+?=
 =?us-ascii?q?GMUdBwZW0VDNIJ?=
X-IronPort-Anti-Spam-Filtered: true
X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0H/AQDRu9NfhwMP04xigQmBT4EjgQA?=
 =?us-ascii?q?YAWNZAR4DBzaEP4kEiBoDh2uHfopPFIEsMxQBAQIBAQEBAQkYAQwIAgQBAQE?=
 =?us-ascii?q?BhksfBg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JkV+EY4E0KQSBF3AfLjAIO4JpPw4BAgECDQIBAgMBAgICA?=
 =?us-ascii?q?QECAgEBAgICAQIBjiIXg06CboImhUZAATE3AgYBCQEBAwlbIYdogW0BAQ?=
X-MGA-submission: =?us-ascii?q?MDG5hpyfpNsP5nP8hpHjwIpvM5sR/bH3fVkcsS?=
 =?us-ascii?q?oy1Gs3mG9IoK+sDIt0SEo6OZ0FoA+qRTaSRJSP5oOCV1E4M6aS+hZe3o?=
 =?us-ascii?q?jyTWyGQar0iJiX+N18jyouu876eCAlgpHwwnA=3D?=
Received: from osgeo6.osgeo.osuosl.org (HELO lists.osgeo.org) ([140.211.15.3])
  by mx201.skynet.be with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 11 Dec 2020 19:39:19 +0100
Received: from osgeo6.osgeo.osuosl.org (localhost [127.0.0.1])
	by lists.osgeo.org (Postfix) with ESMTP id 8FE21611D152;
	Fri, 11 Dec 2020 10:39:12 -0800 (PST)
X-Greylist: delayed 452 seconds by postgrey-1.35 at osgeo6;
 Fri, 11 Dec 2020 10:39:10 PST
Received: from polaris.osa.pri.ee (osa.pri.ee [213.219.84.188])
 by lists.osgeo.org (Postfix) with ESMTP id BF983614592A
 for <tiff@lists.osgeo.org>; Fri, 11 Dec 2020 10:39:10 -0800 (PST)
Received: from localhost (localhost [127.0.0.1])
 by polaris.osa.pri.ee (Postfix) with ESMTP id CC4B16E652
 for <tiff@lists.osgeo.org>; Fri, 11 Dec 2020 20:24:52 +0200 (EET)
X-Virus-Scanned: amavisd-new at osa.pri.ee
Received: from polaris.osa.pri.ee ([127.0.0.1])
 by localhost (osa.pri.ee [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 8Gwo5OTajtBM for <tiff@lists.osgeo.org>;
 Fri, 11 Dec 2020 20:23:59 +0200 (EET)
Received: from TALLL011 (97-169-190-90.dyn.estpak.ee [90.190.169.97])
 (using TLSv1 with cipher AES256-SHA (256/256 bits))
 (Client did not present a certificate)
 by polaris.osa.pri.ee (Postfix) with ESMTPSA id 352546E693
 for <tiff@lists.osgeo.org>; Fri, 11 Dec 2020 20:23:59 +0200 (EET)
To: <tiff@lists.osgeo.org>
References: <TA_bR2wBAP73tCBmxtqD3poMZ_FfgVApv5H-Gj_V-HvMHz9NL12ZeWdXRiIw719viU_OPReHQ1xOkftB4mZDH__ghu8h7SWS8h5hC1H0Ezk=@protonmail.com>
In-Reply-To: <TA_bR2wBAP73tCBmxtqD3poMZ_FfgVApv5H-Gj_V-HvMHz9NL12ZeWdXRiIw719viU_OPReHQ1xOkftB4mZDH__ghu8h7SWS8h5hC1H0Ezk=@protonmail.com>
Date: Fri, 11 Dec 2020 20:30:40 +0200
Message-ID: <011001d6cfeb$bc095240$341bf6c0$@osa.pri.ee>
MIME-Version: 1.0
X-Mailer: Microsoft Outlook 16.0
Thread-Index: AQKDGDsR/JmMr3Y50cafyVKJim5lK6iZoq8Q
Content-Language: et
Subject: Re: [Tiff] SIGSEGV within TIFFGetField()
X-BeenThere: tiff@lists.osgeo.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: TIFF and libtiff discussion <tiff.lists.osgeo.org>
List-Unsubscribe: <https://lists.osgeo.org/mailman/options/tiff>,
 <mailto:tiff-request@lists.osgeo.org?subject=unsubscribe>
List-Post: <mailto:tiff@lists.osgeo.org>
List-Help: <mailto:tiff-request@lists.osgeo.org?subject=help>
List-Subscribe: <https://lists.osgeo.org/mailman/listinfo/tiff>,
 <mailto:tiff-request@lists.osgeo.org?subject=subscribe>
From: paavo--- via Tiff <tiff@lists.osgeo.org>
Reply-To: paavo@osa.pri.ee
Content-Type: multipart/mixed; boundary="===============3403414419294275713=="
Errors-To: tiff-bounces@lists.osgeo.org
Sender: "Tiff" <tiff-bounces@lists.osgeo.org>

This is a multipart message in MIME format.

--===============3403414419294275713==
Content-Type: multipart/alternative;
	boundary="----=_NextPart_000_0111_01D6CFFC.7F92E590"
Content-Language: et

This is a multipart message in MIME format.

------=_NextPart_000_0111_01D6CFFC.7F92E590
Content-Type: text/plain;
	charset="utf-8"
Content-Transfer-Encoding: quoted-printable

LibTIFF has a braindead interface where it is not possible to read =
arbitrary field values according to their type even though the type is =
encoded clearly in the TIFF file. Instead, you have to know exactly how =
to call TIFFGetField() for each standard tag. But that does not work for =
custom tags. For a custom tag you have to call TIFFGetField() with 4 =
arguments:

                           std::uint32_t value_count =3D 0;

                           void* raw_data =3D nullptr;

                           if(TIFFGetField(tif, tiffTag, &value_count, =
&raw_data)=3D=3D1) {

=20

and interpret the result according to TIFFField info:

=20

              const TIFFField *fip =3D ...

              if(fip->field_type =3D=3D ::TIFF_ASCII) {

                     std::string result(static_cast<const =
char*>(raw_data), value_count);

=20

HTH

Paavo

=20

=20

From: Tiff <tiff-bounces@lists.osgeo.org> On Behalf Of OnlineCop via =
Tiff
Sent: reede, 11. detsember 2020 17:23
To: tiff@lists.osgeo.org
Subject: [Tiff] SIGSEGV within TIFFGetField()

=20

My C++ application is terminating with SIGSEGV when I call =
TIFFGetField().

=20

I cloned libtiff's master branch from https://gitlab.com/libtiff/libtiff =
and compiled with debugging. The VERSION file there says it's version =
4.1.0.

=20

gdb reports the SIGSEGV is in tif_dir.c line 1157:

https://gitlab.com/libtiff/libtiff/-/blob/master/libtiff/tif_dir.c#L1157

=20

I'm defining almost identical tags that were reported in =
https://stackoverflow.com/a/27609465/801098 answer and registering them =
with TIFFMergeFieldInfo().

=20

Then I loop over each of the tags I've created and call TIFFGetField(). =
For TIFF_ASCII types, I pass 3 parameters: the TIFF* pointer, the =
(custom) tag, and an [out] (void*) pointer where the value will be =
stored. For non-TIFF_ASCII types, I pass 4 parameters: the TIFF* =
pointer, the (custom) tag, an [out] (uint16_t*) pointer for the count, =
and an [out] (void*) pointer for the value.

=20

The non-TIFF_ASCII types process just fine. The TIFF_ASCII types, =
however, get a segmentation fault.

=20

I've posted some abbreviated code from my files (only the pertinent =
portions that relate to TIFF) at =
https://repl.it/@OnlineCop/SigsegvInTiff#main.cpp, but if it's easier =
for me to include that in an email, let me know and I can paste it. (I =
don't believe the code compiles there, as it doesn't link to the actual =
tiff*.h files.)

=20

My code is being adapted from about 10-year-old code, so it's very =
possible that this worked with an older version of libTIFF, but has =
since changed. Any feedback is appreciated.

=20

@onlinecop

=20

=20


------=_NextPart_000_0111_01D6CFFC.7F92E590
Content-Type: text/html;
	charset="utf-8"
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" =
xmlns=3D"http://www.w3.org/TR/REC-html40"><head><meta =
http-equiv=3DContent-Type content=3D"text/html; charset=3Dutf-8"><meta =
name=3DGenerator content=3D"Microsoft Word 15 (filtered =
medium)"><style><!--
/* Font Definitions */
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Consolas;
	panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-family:"Calibri",sans-serif;}
@page WordSection1
	{size:612.0pt 792.0pt;
	margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]--></head><body lang=3DEN-US link=3Dblue =
vlink=3Dpurple><div class=3DWordSection1><p class=3DMsoNormal =
style=3D'text-autospace:none'>LibTIFF has a braindead interface where it =
is not possible to read arbitrary field values according to their type =
even though the type is encoded clearly in the TIFF file. Instead, you =
have to know exactly how to call TIFFGetField() for each standard tag. =
But that does not work for custom tags. For a custom tag you have to =
call TIFFGetField() with 4 arguments:<br><br><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:black'>=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
</span><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:#2B91AF'>std::uint32_=
t</span><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:black'> value_count =
=3D 0;<o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:black'>=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
</span><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:blue'>void</span><spa=
n style=3D'font-size:9.5pt;font-family:Consolas;color:black'>* raw_data =
=3D </span><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:#6F008A'>nullptr</spa=
n><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:black'>;<o:p></o:p></=
span></p><p class=3DMsoNormal style=3D'text-autospace:none'><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:black'>=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
</span><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:blue'>if</span><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:black'>(TIFFGetField(=
</span><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:gray'>tif</span><span=
 style=3D'font-size:9.5pt;font-family:Consolas;color:black'>, =
</span><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:gray'>tiffTag</span><=
span style=3D'font-size:9.5pt;font-family:Consolas;color:black'>, =
&amp;value_count, &amp;raw_data)=3D=3D1) {<o:p></o:p></span></p><p =
class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal>and =
interpret the result according to <span =
style=3D'font-size:9.5pt;font-family:Consolas;color:#2B91AF'>TIFFField =
</span>info:<o:p></o:p></p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><p =
class=3DMsoNormal style=3D'text-autospace:none'><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:black'>=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 </span><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:blue'>const</span><sp=
an style=3D'font-size:9.5pt;font-family:Consolas;color:black'> =
</span><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:#2B91AF'>TIFFField</s=
pan><span style=3D'font-size:9.5pt;font-family:Consolas;color:black'> =
*</span><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:gray'>fip =3D =
...<o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:black'>=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
</span><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:blue'>if</span><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:black'>(</span><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:gray'>fip</span><span=
 =
style=3D'font-size:9.5pt;font-family:Consolas;color:black'>-&gt;field_typ=
e =3D=3D ::</span><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:darkslategray'>TIFF_A=
SCII</span><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:black'>) =
{<o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'text-autospace:none'><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:black'>=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 </span><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:#2B91AF'>std::string<=
/span><span style=3D'font-size:9.5pt;font-family:Consolas;color:black'> =
result(</span><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:blue'>static_cast</sp=
an><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:black'>&lt;</span><sp=
an =
style=3D'font-size:9.5pt;font-family:Consolas;color:blue'>const</span><sp=
an style=3D'font-size:9.5pt;font-family:Consolas;color:black'> =
</span><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:blue'>char</span><spa=
n =
style=3D'font-size:9.5pt;font-family:Consolas;color:black'>*&gt;(</span><=
span =
style=3D'font-size:9.5pt;font-family:Consolas;color:gray'>raw_data</span>=
<span style=3D'font-size:9.5pt;font-family:Consolas;color:black'>), =
</span><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:gray'>value_count</sp=
an><span =
style=3D'font-size:9.5pt;font-family:Consolas;color:black'>);<o:p></o:p><=
/span></p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><p =
class=3DMsoNormal>HTH<o:p></o:p></p><p =
class=3DMsoNormal>Paavo<o:p></o:p></p><p =
class=3DMsoNormal><o:p>&nbsp;</o:p></p><p =
class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal><b>From:</b> =
Tiff &lt;tiff-bounces@lists.osgeo.org&gt; <b>On Behalf Of </b>OnlineCop =
via Tiff<br><b>Sent:</b> reede, 11. detsember 2020 17:23<br><b>To:</b> =
tiff@lists.osgeo.org<br><b>Subject:</b> [Tiff] SIGSEGV within =
TIFFGetField()<o:p></o:p></p><p =
class=3DMsoNormal><o:p>&nbsp;</o:p></p><div><p class=3DMsoNormal =
style=3D'background:white'><span =
style=3D'font-size:10.5pt;font-family:"Arial",sans-serif;color:#555555'>M=
y C++ application is terminating with SIGSEGV when I call =
TIFFGetField().<o:p></o:p></span></p></div><div><p class=3DMsoNormal =
style=3D'background:white'><span =
style=3D'font-size:10.5pt;font-family:"Arial",sans-serif;color:#555555'><=
o:p>&nbsp;</o:p></span></p></div><div><p class=3DMsoNormal =
style=3D'background:white'><span =
style=3D'font-size:10.5pt;font-family:"Arial",sans-serif;color:#555555'>I=
 cloned libtiff's master branch from&nbsp;<a =
href=3D"https://gitlab.com/libtiff/libtiff" =
target=3D"_blank">https://gitlab.com/libtiff/libtiff</a>&nbsp;and =
compiled with debugging. The VERSION file there says it's version =
4.1.0.<o:p></o:p></span></p></div><div><p class=3DMsoNormal =
style=3D'background:white'><span =
style=3D'font-size:10.5pt;font-family:"Arial",sans-serif;color:#555555'><=
o:p>&nbsp;</o:p></span></p></div><div><p class=3DMsoNormal =
style=3D'background:white'><span =
style=3D'font-size:10.5pt;font-family:"Arial",sans-serif;color:#555555'>g=
db reports the SIGSEGV is in tif_dir.c line =
1157:<o:p></o:p></span></p></div><div><p class=3DMsoNormal =
style=3D'background:white'><span =
style=3D'font-size:10.5pt;font-family:"Arial",sans-serif;color:#555555'><=
a =
href=3D"https://gitlab.com/libtiff/libtiff/-/blob/master/libtiff/tif_dir.=
c#L1157" =
target=3D"_blank">https://gitlab.com/libtiff/libtiff/-/blob/master/libtif=
f/tif_dir.c#L1157</a><o:p></o:p></span></p></div><div><p =
class=3DMsoNormal style=3D'background:white'><span =
style=3D'font-size:10.5pt;font-family:"Arial",sans-serif;color:#555555'><=
o:p>&nbsp;</o:p></span></p></div><div><p class=3DMsoNormal =
style=3D'background:white'><span =
style=3D'font-size:10.5pt;font-family:"Arial",sans-serif;color:#555555'>I=
'm defining almost identical tags that were reported in&nbsp;<a =
href=3D"https://stackoverflow.com/a/27609465/801098" =
target=3D"_blank">https://stackoverflow.com/a/27609465/801098</a>&nbsp;an=
swer and registering them with =
TIFFMergeFieldInfo().<o:p></o:p></span></p></div><div><p =
class=3DMsoNormal style=3D'background:white'><span =
style=3D'font-size:10.5pt;font-family:"Arial",sans-serif;color:#555555'><=
o:p>&nbsp;</o:p></span></p></div><div><p class=3DMsoNormal =
style=3D'background:white'><span =
style=3D'font-size:10.5pt;font-family:"Arial",sans-serif;color:#555555'>T=
hen I loop over each of the tags I've created and call TIFFGetField(). =
For TIFF_ASCII types, I pass 3 parameters: the TIFF* pointer, the =
(custom) tag, and an [out] (void*) pointer where the value will be =
stored. For non-TIFF_ASCII types, I pass 4 parameters: the TIFF* =
pointer, the (custom) tag, an [out] (uint16_t*) pointer for the count, =
and an [out] (void*) pointer for the =
value.<o:p></o:p></span></p></div><div><p class=3DMsoNormal =
style=3D'background:white'><span =
style=3D'font-size:10.5pt;font-family:"Arial",sans-serif;color:#555555'><=
o:p>&nbsp;</o:p></span></p></div><div><p class=3DMsoNormal =
style=3D'background:white'><span =
style=3D'font-size:10.5pt;font-family:"Arial",sans-serif;color:#555555'>T=
he non-TIFF_ASCII types process just fine. The TIFF_ASCII types, =
however, get a segmentation fault.<o:p></o:p></span></p></div><div><p =
class=3DMsoNormal style=3D'background:white'><span =
style=3D'font-size:10.5pt;font-family:"Arial",sans-serif;color:#555555'><=
o:p>&nbsp;</o:p></span></p></div><div><p class=3DMsoNormal =
style=3D'background:white'><span =
style=3D'font-size:10.5pt;font-family:"Arial",sans-serif;color:#555555'>I=
've posted some abbreviated code from my files (only the pertinent =
portions that relate to TIFF) at&nbsp;<a =
href=3D"https://repl.it/@OnlineCop/SigsegvInTiff#main.cpp" =
target=3D"_blank">https://repl.it/@OnlineCop/SigsegvInTiff#main.cpp</a>, =
but if it's easier for me to include that in an email, let me know and I =
can paste it. (I don't believe the code compiles there, as it doesn't =
link to the actual tiff*.h files.)<o:p></o:p></span></p></div><div><p =
class=3DMsoNormal style=3D'background:white'><span =
style=3D'font-size:10.5pt;font-family:"Arial",sans-serif;color:#555555'><=
o:p>&nbsp;</o:p></span></p></div><div><p class=3DMsoNormal =
style=3D'background:white'><span =
style=3D'font-size:10.5pt;font-family:"Arial",sans-serif;color:#555555'>M=
y code is being adapted from about 10-year-old code, so it's very =
possible that this worked with an older version of libTIFF, but has =
since changed. Any feedback is =
appreciated.<o:p></o:p></span></p></div><div><p class=3DMsoNormal =
style=3D'background:white'><span =
style=3D'font-size:10.5pt;font-family:"Arial",sans-serif;color:#555555'><=
o:p>&nbsp;</o:p></span></p></div><div><div><p class=3DMsoNormal =
style=3D'background:white'><span =
style=3D'font-size:10.5pt;font-family:"Arial",sans-serif;color:#555555'>@=
onlinecop<o:p></o:p></span></p></div></div><div><div><p =
class=3DMsoNormal><o:p>&nbsp;</o:p></p></div></div><div><p =
class=3DMsoNormal><o:p>&nbsp;</o:p></p></div></div></body></html>
------=_NextPart_000_0111_01D6CFFC.7F92E590--


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

_______________________________________________
Tiff mailing list
Tiff@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/tiff

--===============3403414419294275713==--

