View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0011812 | libextractor | libextractor main library | public | 2026-09-19 23:27 | 2026-09-19 23:27 |
| Reporter | olly | Assigned To | |||
| Priority | normal | Severity | minor | Reproducibility | always |
| Status | new | Resolution | open | ||
| Product Version | 1.19 | ||||
| Summary | 0011812: data_len is not always strlen (data)+1 | ||||
| Description | The documentation says for both EXTRACTOR_METAFORMAT_UTF8 and EXTRACTOR_METAFORMAT_C_STRING that `"data_len" is strlen(data)+1`. However this is not always the case. | ||||
| Steps To Reproduce | Test program `extractor-data_len-test.c`: ``` #include <extractor.h> #include <stdio.h> #include <string.h> static int f(void*, const char*, enum EXTRACTOR_MetaType, enum EXTRACTOR_MetaFormat format, const char*, const char* data, size_t data_len) { const char* encoding = NULL; switch (format) { case EXTRACTOR_METAFORMAT_UTF8: encoding ="EXTRACTOR_METAFORMAT_UTF8"; break; case EXTRACTOR_METAFORMAT_C_STRING: encoding ="EXTRACTOR_METAFORMAT_C_STRING"; break; default: return 0; } // Documentation says "data_len is strlen (data)+1" for // EXTRACTOR_METAFORMAT_UTF8 and EXTRACTOR_METAFORMAT_C_STRING. if (data[data_len - 1] != '\0') { printf("data[data_len - 1] != '\\0' for %s\n", encoding); return 0; } if (data_len != strlen(data) + 1) { printf("data_len != strlen(data) + 1, apparently due to embedded zero bytes, for %s\n", encoding); return 0; } return 0; } int main(int argc, char ** argv) { (void)argc; // Add all default plugins. struct EXTRACTOR_PluginList* plugins = EXTRACTOR_plugin_add_defaults(EXTRACTOR_OPTION_DEFAULT_POLICY); if (plugins == nullptr) { printf("Failed to find any libextractor plugins\n"); return 1; } while (*++argv) { printf("%s:\n", *argv); EXTRACTOR_extract(plugins, *argv, NULL, 0, &f, NULL); } } ``` Compile using `gcc -Wall -W -O2 extractor-data_len-test.c $(pkg-config libextractor --libs)` Then: ``` $ ./a.out /usr/share/wv/wingdingfont/161.gif /usr/share/wv/wingdingfont/161.gif: data[data_len - 1] != '\0' for EXTRACTOR_METAFORMAT_C_STRING ``` I'm attaching `161.gif` which is just the smallest GIF file I have to hand (and is from the Debian wv package so should be freely redistributable). This seems to be true for all GIF files I've tested. It seems that `data_len == strlen(data)` for these rather than it being due to embedded zero bytes in the value. | ||||
| Additional Information | A workaround user code can use (after checking the type is EXTRACTOR_METAFORMAT_UTF8 or EXTRACTOR_METAFORMAT_C_STRING) is: ``` if (data[data_len - 1] != '\0') ++data_len; ``` Alternatively ignore `data_len` and treat the value as a zero-terminated string. | ||||
| Tags | No tags attached. | ||||
| Attached Files | |||||