openzim / zim-tools

Various ZIM command line tools
https://download.openzim.org/release/zim-tools/
GNU General Public License v3.0
123 stars 34 forks source link

Use search regex instead of match for metadata check. #369

Closed mgautierfr closed 1 year ago

mgautierfr commented 1 year ago

Fix #345 Fix #352

Investigating #345, it seems that zimcheck-test is getting a segfault (when run with qemu-aarch64) in std::regex_match and the PNG_REGEXP_DATA. It appears the segfault happens with a huge callstack. I don't know where the bug is exactly (qemu ? std ?) but the behavior is the same than #352.

By using regex_search we allow the regex to not match the whole content (but still allow it if the regex ends with $)

As we don't need to check all the PNG data, and check only the beginning, regex_search is passing without segfault (early exit ?)

This PR take another approach than #358 by fixing the regex instead of avoiding it (but it doesn't check for the size) (To be honest, I've made this fix before realizing that it was fixing the same bug than #352)

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 33.33% and no project coverage change.

Comparison is base (dc703e0) 27.72% compared to head (b0a2e0f) 27.72%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #369 +/- ## ======================================= Coverage 27.72% 27.72% ======================================= Files 26 26 Lines 2528 2528 Branches 1349 1349 ======================================= Hits 701 701 Misses 1346 1346 Partials 481 481 ``` | [Files Changed](https://app.codecov.io/gh/openzim/zim-tools/pull/369?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=openzim) | Coverage Δ | | |---|---|---| | [src/metadata.cpp](https://app.codecov.io/gh/openzim/zim-tools/pull/369?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=openzim#diff-c3JjL21ldGFkYXRhLmNwcA==) | `59.74% <33.33%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.