GithubHelp home page GithubHelp logo

gpertea / gclib Goto Github PK

View Code? Open in Web Editor NEW
32.0 32.0 13.0 1.09 MB

GCLib - Genomic C++ library of reusable code for bioinformatics projects

License: Other

C++ 79.57% Makefile 0.35% C 20.05% Shell 0.03%

gclib's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gclib's Issues

add support for multiple codon tables

Originally posted by @Maarten-vd-Sande in gpertea/gffread#21 (comment)

Just dropping in to say that supporting multiple tables would be an awesome feature (for me). I haven't found any other tool that works as easy and fast as gffread.

Would you support a PR in this direction, if so, can you give some pointers? It's been over 5 years since I did anything serious with C++ so it might not result into anything useful though 😇 .. I can't seem to find where the table is defined..

static char codonData[]={ //long list of 3+1 characters (codon+translation)

Uninitialized GFF line info causes out-of-bounds-read, possible out-of-bounds-write.

Reproduce

PoC Input: min.gz

Steps to Reproduce:

  1. Compile GffRead v0.12.7 (will fetch GCLib v0.12.7)
  2. Decompress PoC input: gzip -d min.gz
  3. Run: ./gffread -E min -o out

Output:

Command line was:
./gffread -E min -o out
Segmentation fault

Root Cause

gclib/gff.cpp

Lines 413 to 432 in 8aee376

while (line[i]!=0) {
if (line[i]=='\t') {
line[i]=0;
t[tidx]=line+i+1;
tidx++;
//if (tidx>8) break;
}
i++;
}
if (tidx<8) { // ignore non-GFF lines
return;
}
if (tidx>9) {
GMessage("Warning: unexpected tab character in last column, line truncated:\n\%s\n",l);
}
gffWarnings=reader->gff_warns;
gseqname=t[0];
track=t[1];
ftype=t[2];
info=t[8];

When GCLib reads a GFF line with no info segment, the char * at t[8] will not be set, causing it to take on whatever stale value happens to be in that location of the stack. Triggered accidentally, this can cause a segfault due to reading an invalid address here:

gclib/gff.cpp

Line 118 in 8aee376

while (notfound && *pos) {

However, a maliciously crafted input may be able to place a valid pointer at this location, causing a more severe vulnerability.

Proposed Patch

At a minimum, t should be zeroed during initialization:

*** v0.12.7/gclib/gff.cpp     2021-07-23 10:31:39.000000000 -0400
--- new/gclib/gff.cpp       2021-10-04 10:54:52.989309121 -0400
*************** GffLine::GffLine(GffReader* reader, cons
*** 405,411 ****
   GMALLOC(dupline, llen+1);
   memcpy(dupline, l, llen+1);
   skipLine=true; //clear only if we make it to the end of this function
!  char* t[9];
   int i=0;
   int tidx=1;
   t[0]=line;
--- 405,411 ----
   GMALLOC(dupline, llen+1);
   memcpy(dupline, l, llen+1);
   skipLine=true; //clear only if we make it to the end of this function
!  char* t[9] = {0};
   int i=0;
   int tidx=1;
   t[0]=line;

Ideally, the library should gracefully handle no info being found (this only works if t is zero initialized):

*** v0.12.7/gclib/gff.cpp     2021-07-23 10:31:39.000000000 -0400
--- new/gclib/gff.cpp       2021-10-04 10:54:52.989309121 -0400
*************** GffLine::GffLine(GffReader* reader, cons
*** 430,435 ****
--- 430,439 ----
   track=t[1];
   ftype=t[2];
   info=t[8];
+  if (!info) {
+    GMessage("Warning: missing info:\n%s\n",l);
+    return;
+  }
   char* p=t[3];
   if (!parseUInt(p,fstart)) {
     //chromosome_band entries in Flybase

Credit

This bug was detected using AFL and localized using ARCUS.

g++ warnings -

Hello,

Admittedly, I do not see any immediate need to address any of these warnings.

Kind regards,
Steffen

$ gcc --version
gcc (Debian 10.2.0-3) 10.2.0
libtool: compile:  g++ -DHAVE_CONFIG_H -I. -I. -Wdate-time -D_FORTIFY_SOURCE=2 -g -O2 -fdebug-prefix-map=/home/moeller/git/med-team/libgclib=. -fstack-protector-strong -Wformat -Werror=format-security -Wall -pedantic -flto -fPIC -D_FILE_OFFSET_BITS=64 -c GStr.cpp  -fPIC -DPIC -o .libs/libgclib_la-GStr.o
In file included from gff.cpp:1:
gff.h:229:13: warning: ISO C++ prohibits anonymous structs [-Wpedantic]
  229 |      struct {
      |             ^
gff.h:232:13: warning: ISO C++ prohibits anonymous structs [-Wpedantic]
  232 |      struct {
      |             ^
gff.h:328:12: warning: ISO C++ prohibits anonymous structs [-Wpedantic]
  328 |     struct {
      |            ^
gff.h:691:14: warning: ISO C++ prohibits anonymous structs [-Wpedantic]
  691 |       struct {
      |              ^
gff.h:1150:12: warning: ISO C++ prohibits anonymous structs [-Wpedantic]
 1150 |     struct {
      |            ^
In file included from GList.hh:8,
                 from GFastaIndex.h:12,
                 from GFaSeqGet.h:3,
                 from gff.h:9,
                 from gff.cpp:1:
GVec.hh: In instantiation of ‘void GVec<OBJ>::setCapacity(int) [with OBJ = GMapSeg]’:
GVec.hh:202:3:   required from ‘GVec<OBJ>::GVec(int) [with OBJ = GMapSeg]’
gff.h:127:50:   required from here
GVec.hh:291:15: warning: ‘void* memset(void*, int, size_t)’ clearing an object of non-trivial type ‘class GMapSeg’; use assignment or value-initialization instead [-Wclass-memaccess]
  291 |         memset(fArray+fCount, 0, (NewCapacity-fCount)*sizeof(OBJ));
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from gff.cpp:1:
gff.h:70:7: note: ‘class GMapSeg’ declared here
   70 | class GMapSeg:public GSeg {
      |       ^~~~~~~
In file included from GList.hh:8,
                 from GFastaIndex.h:12,
                 from GFaSeqGet.h:3,
                 from gff.h:9,
                 from gff.cpp:1:
GVec.hh: In instantiation of ‘void GVec<OBJ>::setCapacity(int) [with OBJ = GSeg]’:
GVec.hh:202:3:   required from ‘GVec<OBJ>::GVec(int) [with OBJ = GSeg]’
gff.h:311:92:   required from here
GVec.hh:291:15: warning: ‘void* memset(void*, int, size_t)’ clearing an object of non-trivial type ‘class GSeg’; use assignment or value-initialization instead [-Wclass-memaccess]
  291 |         memset(fArray+fCount, 0, (NewCapacity-fCount)*sizeof(OBJ));
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from gff.h:6,
                 from gff.cpp:1:
GBase.h:308:7: note: ‘class GSeg’ declared here
  308 | class GSeg {
      |       ^~~~
In file included from GList.hh:8,
                 from GFastaIndex.h:12,
                 from GFaSeqGet.h:3,
                 from gff.h:9,
                 from gff.cpp:1:
GVec.hh: In instantiation of ‘void GVec<OBJ>::setCapacity(int) [with OBJ = GeneCDS]’:
GVec.hh:202:3:   required from ‘GVec<OBJ>::GVec(int) [with OBJ = GeneCDS]’
gff.h:1351:31:   required from here
GVec.hh:291:15: warning: ‘void* memset(void*, int, size_t)’ clearing an object of non-trivial type ‘class GeneCDS’; use assignment or value-initialization instead [-Wclass-memaccess]
  291 |         memset(fArray+fCount, 0, (NewCapacity-fCount)*sizeof(OBJ));
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from gff.cpp:1:
gff.h:1340:7: note: ‘class GeneCDS’ declared here
 1340 | class GeneCDS: public GSeg {
      |       ^~~~~~~
In file included from GList.hh:8,
                 from GFastaIndex.h:12,
                 from GFaSeqGet.h:3,
                 from gff.h:9,
                 from gff.cpp:1:
GVec.hh: In instantiation of ‘void GVec<OBJ>::setCapacity(int) [with OBJ = GffExon]’:
GVec.hh:202:3:   required from ‘GVec<OBJ>::GVec(int) [with OBJ = GffExon]’
gff.cpp:2315:16:   required from here
GVec.hh:291:15: warning: ‘void* memset(void*, int, size_t)’ clearing an object of non-trivial type ‘class GffExon’; use assignment or value-initialization instead [-Wclass-memaccess]
  291 |         memset(fArray+fCount, 0, (NewCapacity-fCount)*sizeof(OBJ));
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from gff.cpp:1:
gff.h:629:7: note: ‘class GffExon’ declared here
  629 | class GffExon : public GSeg {
      |       ^~~~~~~
In file included from GList.hh:8,
                 from GFastaIndex.h:12,
                 from GFaSeqGet.h:3,
                 from gff.h:9,
                 from gff.cpp:1:
GVec.hh: In instantiation of ‘void GVec<OBJ>::setCapacity(int) [with OBJ = GSegMatch]’:
GVec.hh:202:3:   required from ‘GVec<OBJ>::GVec(int) [with OBJ = GSegMatch]’
GList.hh:191:76:   required from ‘GArray<OBJ>::GArray(int (*)(pointer, pointer)) [with OBJ = GSegMatch; GCompareProc = int(void*, void*); pointer = void*]’
gff.h:1351:31:   required from here
GVec.hh:291:15: warning: ‘void* memset(void*, int, size_t)’ clearing an object of non-trivial type ‘class GSegMatch’; use assignment or value-initialization instead [-Wclass-memaccess]
  291 |         memset(fArray+fCount, 0, (NewCapacity-fCount)*sizeof(OBJ));
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from gff.cpp:1:
gff.h:1328:7: note: ‘class GSegMatch’ declared here
 1328 | class GSegMatch { //keep track of "matching" overlaps of a GeneCDSChain with multiple GeneSegment containers
      |       ^~~~~~~~~
In file included from GList.hh:8,
                 from GFastaIndex.h:12,
                 from GFaSeqGet.h:3,
                 from gff.h:9,
                 from gff.cpp:1:
GVec.hh: In instantiation of ‘void GVec<OBJ>::Grow(int, OBJ&) [with OBJ = GSegMatch]’:
GVec.hh:437:9:   required from ‘void GVec<OBJ>::Insert(int, OBJ*) [with OBJ = GSegMatch]’
GVec.hh:69:44:   required from ‘void GVec<OBJ>::Insert(int, OBJ) [with OBJ = GSegMatch]’
GList.hh:234:21:   required from ‘int GArray<OBJ>::Add(OBJ*) [with OBJ = GSegMatch]’
GList.hh:51:36:   required from ‘int GArray<OBJ>::Add(OBJ&) [with OBJ = GSegMatch]’
gff.h:1364:22:   required from here
GVec.hh:358:15: warning: ‘void* memset(void*, int, size_t)’ clearing an object of non-trivial type ‘class GSegMatch’; use assignment or value-initialization instead [-Wclass-memaccess]
  358 |         memset(&newList[fCount+1], 0, (NewCapacity-fCount-1)*sizeof(OBJ));
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from gff.cpp:1:
gff.h:1328:7: note: ‘class GSegMatch’ declared here
 1328 | class GSegMatch { //keep track of "matching" overlaps of a GeneCDSChain with multiple GeneSegment containers
      |       ^~~~~~~~~

tag a release

Can you please tag a release of this software? We'd like to user gffread and build it consistently with a tagged version of this lib. Tags are much nicer than using commit hashes...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.