Commit 579fec22e4f2eaabf03d54ace845ce97f31bf815
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,15 +77,20 @@ janus_error janus_finalize_template(janus_template template_, janus_flat_templat | ||
| 77 | { | 77 | { |
| 78 | *bytes = 0; | 78 | *bytes = 0; |
| 79 | foreach (const cv::Mat &m, *template_) { | 79 | foreach (const cv::Mat &m, *template_) { |
| 80 | - assert(m.isContinuous()); | 80 | + if (!m.isContinuous()) |
| 81 | + return JANUS_UNKNOWN_ERROR; | ||
| 82 | + | ||
| 81 | const size_t templateBytes = m.rows * m.cols * m.elemSize(); | 83 | const size_t templateBytes = m.rows * m.cols * m.elemSize(); |
| 82 | if (*bytes + sizeof(size_t) + templateBytes > janus_max_template_size()) | 84 | if (*bytes + sizeof(size_t) + templateBytes > janus_max_template_size()) |
| 83 | break; | 85 | break; |
| 86 | + | ||
| 84 | memcpy(flat_template, &templateBytes, sizeof(templateBytes)); | 87 | memcpy(flat_template, &templateBytes, sizeof(templateBytes)); |
| 85 | flat_template += sizeof(templateBytes); | 88 | flat_template += sizeof(templateBytes); |
| 89 | + *bytes += sizeof(templateBytes); | ||
| 90 | + | ||
| 86 | memcpy(flat_template, m.data, templateBytes); | 91 | memcpy(flat_template, m.data, templateBytes); |
| 87 | flat_template += templateBytes; | 92 | flat_template += templateBytes; |
| 88 | - *bytes += sizeof(size_t) + templateBytes; | 93 | + *bytes += templateBytes; |
| 89 | } | 94 | } |
| 90 | 95 | ||
| 91 | delete template_; | 96 | delete template_; |