#3 Fix member read size mistake, especially on big endian (#1930943)
Closed 2 years ago by rathann. Opened 2 years ago by mtasaka.
rpms/ mtasaka/inchi s390x-fix  into  rawhide

@@ -0,0 +1,62 @@ 

+ From 26351733bde20eb16aedd62b4b64a2417615020e Mon Sep 17 00:00:00 2001

+ From: Mamoru TASAKA <mtasaka@fedoraproject.org>

+ Date: Thu, 25 Nov 2021 23:07:31 +0900

+ Subject: [PATCH] MolfileReadCountsLine: fix storing n_atoms, n_bonds members

+  after reading short size

+ 

+ In MolfileReadCountsLine() (in INCHI_BASE/src/mol_fmt1.c), currently

+ ctab->n_atoms and ctab->n_bonds, which have int type (as defined in src/mol_fmt.h),

+ are passed to be MolfileReadField(), and to be treated there as if they have

+ short size (as MOL_FMT_SHORT_INT_DATA is also passed to the argument of

+ MolfileReadField(), and also the comment shows).

+ 

+ This causes a error on big endian system such as s390x, where for example

+ reading the line:

+ 

+ 1  0  0  0  0  0  0  0  0  0999 V2000

+ 

+ On little endian (64bit) system, ctab->n_atoms is correctly stored as 1, but on

+ s390x (big endian 64bit) system, ctab->n_atoms gets 65536 (= 1<<16), which is

+ unexpected.

+ 

+ To fix this, once store the read value to short size local variable, then

+ copy the value to ctab->n_atoms or so later.

+ ---

+  INCHI_BASE/src/mol_fmt1.c | 7 +++++--

+  1 file changed, 5 insertions(+), 2 deletions(-)

+ 

+ diff --git a/INCHI_BASE/src/mol_fmt1.c b/INCHI_BASE/src/mol_fmt1.c

+ index 41ed15e..c2ad11a 100644

+ --- a/INCHI_BASE/src/mol_fmt1.c

+ +++ b/INCHI_BASE/src/mol_fmt1.c

+ @@ -572,6 +572,7 @@ int MolfileReadCountsLine( MOL_FMT_CTAB* ctab,

+      char line[MOL_FMT_INPLINELEN];

+      const int line_len = sizeof( line );

+      int   err = 0, len;

+ +    short n_atoms, n_bonds;

+  

+      p = inchi_fgetsLf( line, line_len, inp_file );

+  

+ @@ -588,8 +589,8 @@ int MolfileReadCountsLine( MOL_FMT_CTAB* ctab,

+          TREAT_ERR( err, 0, "Too long counts line" );  /* too long input file line */

+      }

+  

+ -    if (0 > MolfileReadField( &ctab->n_atoms, 3, MOL_FMT_SHORT_INT_DATA, &p ) /* V2000 only: short int */

+ -         || 0 > MolfileReadField( &ctab->n_bonds, 3, MOL_FMT_SHORT_INT_DATA, &p ) /* V2000 only: short int */

+ +    if (0 > MolfileReadField( &n_atoms, 3, MOL_FMT_SHORT_INT_DATA, &p ) /* V2000 only: short int */

+ +         || 0 > MolfileReadField( &n_bonds, 3, MOL_FMT_SHORT_INT_DATA, &p ) /* V2000 only: short int */

+  

+  #if ( MOL_FMT_QUERY == MOL_FMT_PRESENT )

+           || 0 > MolfileReadField( &ctab->n_atom_lists, 3, MOL_FMT_SHORT_INT_DATA, &p )

+ @@ -621,6 +622,8 @@ int MolfileReadCountsLine( MOL_FMT_CTAB* ctab,

+          AddErrorMessage( pStrErr, line );

+          goto err_fin;

+      }

+ +    ctab->n_atoms = n_atoms;

+ +    ctab->n_bonds = n_bonds;

+  

+      /* Get CTFile version (V2000 or other) */

+      len = MolfileReadField( ctab->version_string,

+ -- 

+ 2.33.1

+ 

file modified
+8 -6
@@ -4,12 +4,15 @@ 

  Summary: The IUPAC International Chemical Identifier library

  Name: inchi

  Version: 1.0.6

- Release: 2%{?dist}

+ Release: 3%{?dist}

  URL: https://www.inchi-trust.org/about-the-inchi-standard/

  Source0: https://www.inchi-trust.org/download/%{url_ver}/INCHI-1-SRC.zip

  Source1: https://www.inchi-trust.org/download/%{url_ver}/INCHI-1-DOC.zip

  Source2: https://www.inchi-trust.org/download/%{url_ver}/INCHI-1-TEST.zip

  Patch0: %{name}-rpm.patch

+ # reported upstream:

+ # https://sourceforge.net/p/inchi/bugs/77/

+ Patch1: %{name}-1.0.6-0001-MolfileReadCountsLine-fix-storing-n_atoms-n_bonds-me.patch

  License: LGPLv2+

  BuildRequires: dos2unix

  BuildRequires: gcc
@@ -60,6 +63,7 @@ 

  %prep

  %setup -q -n INCHI-1-SRC -a 1 -a 2

  %patch0 -p1 -b .r

+ %patch1 -p1 -b .big_endian

  for file in readme.txt ; do

    dos2unix -k $file

  done
@@ -95,12 +99,7 @@ 

  for f in inchify_{InChI_TestSet,zzp} ; do

      sh ./${f}.sh

  done

- %ifarch s390x

- # https://bugzilla.redhat.com/show_bug.cgi?id=1930943

- for t in its-*.inc zzp-*.inc ; do diff -u reference/$t $t || : ; done

- %else

  for t in its-*.inc zzp-*.inc ; do diff -u reference/$t $t ; done

- %endif

  popd

  

  %files
@@ -119,6 +118,9 @@ 

  %doc INCHI-1-DOC/*

  

  %changelog

+ * Thu Nov 25 2021 Mamoru TASAKA <mtasaka@fedoraproject.org> - 1.0.6-3

+ - Fix member read size mistake, especially on big endian (#1930943)

+ 

  * Thu Jul 22 2021 Fedora Release Engineering <releng@fedoraproject.org> - 1.0.6-2

  - Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild

  

Build succeeded.

@rathann would you take a look at this?

Yes, thanks a lot for finding the root cause. I want to apply this to F34+, so it cannot be merged as-is. I'll take the patch and apply myself soon.

Pull-Request has been closed by rathann

2 years ago