View Issue Details

IDProjectCategoryView StatusLast Update
0011812libextractorlibextractor main librarypublic2026-09-19 23:27
Reporterolly Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Product Version1.19 
Summary0011812: data_len is not always strlen (data)+1
DescriptionThe 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 ReproduceTest 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 InformationA 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.
TagsNo tags attached.
Attached Files
161.gif (143 bytes)   
161.gif (143 bytes)   

Activities

Issue History

Date Modified Username Field Change
2026-09-19 23:27 olly New Issue
2026-09-19 23:27 olly File Added: 161.gif