Commit 579fec22e4f2eaabf03d54ace845ce97f31bf815

Authored by Josh Klontz
1 parent ce6fe757

janus_finalize_template sanity check

Showing 1 changed file with 7 additions and 2 deletions
openbr/janus.cpp
... ... @@ -77,15 +77,20 @@ janus_error janus_finalize_template(janus_template template_, janus_flat_templat
77 77 {
78 78 *bytes = 0;
79 79 foreach (const cv::Mat &m, *template_) {
80   - assert(m.isContinuous());
  80 + if (!m.isContinuous())
  81 + return JANUS_UNKNOWN_ERROR;
  82 +
81 83 const size_t templateBytes = m.rows * m.cols * m.elemSize();
82 84 if (*bytes + sizeof(size_t) + templateBytes > janus_max_template_size())
83 85 break;
  86 +
84 87 memcpy(flat_template, &templateBytes, sizeof(templateBytes));
85 88 flat_template += sizeof(templateBytes);
  89 + *bytes += sizeof(templateBytes);
  90 +
86 91 memcpy(flat_template, m.data, templateBytes);
87 92 flat_template += templateBytes;
88   - *bytes += sizeof(size_t) + templateBytes;
  93 + *bytes += templateBytes;
89 94 }
90 95  
91 96 delete template_;
... ...