From eb4a04c0f51e3b9df3f6deafb185c5bef693ed6b Mon Sep 17 00:00:00 2001 From: Echelon9 Date: Fri, 29 Aug 2014 01:18:50 +1000 Subject: [PATCH] Fix Issue #174 - ktable.get(wrong_length_string) gives core dump --- khmer/_khmermodule.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/khmer/_khmermodule.cc b/khmer/_khmermodule.cc index 6da6eacca3..b82392b6f8 100644 --- a/khmer/_khmermodule.cc +++ b/khmer/_khmermodule.cc @@ -1367,6 +1367,13 @@ static PyObject * hash_get(PyObject * self, PyObject * args) count = counting->get_count((unsigned int) pos); } else if (PyString_Check(arg)) { std::string s = PyString_AsString(arg); + + if (strlen(s.c_str()) < counting->ksize()) { + PyErr_SetString(PyExc_ValueError, + "string length must >= the hashtable k-mer size"); + return NULL; + } + count = counting->get_count(s.c_str()); } @@ -2328,6 +2335,13 @@ static PyObject * hashbits_get(PyObject * self, PyObject * args) count = hashbits->get_count((unsigned int) pos); } else if (PyString_Check(arg)) { std::string s = PyString_AsString(arg); + + if (strlen(s.c_str()) < hashbits->ksize()) { + PyErr_SetString(PyExc_ValueError, + "string length must >= the hashtable k-mer size"); + return NULL; + } + count = hashbits->get_count(s.c_str()); } else { PyErr_SetString(PyExc_ValueError, "must pass in an int or string");