Package: libmagic1t64
Version: 1:5.46-5
Compile the report.c file in the attachment as documented in the file.
it will give wrong output when using magic_buffer instead of magic_file.
everything is documented in the file.
Running on debian bookworm works, but running on debian trixie gives
wrong result.
Best Regards,
Erik Thiele
/*
compile like this:
gcc -Wall report.c -o report -lmagic
then just start:
./report
if you start the program on debian trixie you get this wrong output:
./report
adding: msg.txt (stored 0%)
output of magic_file: application/zip
output of magic_buffer: application/octet-stream
^^^^ it should be application/zip in BOTH cases! Here is the error!
if you start the program on debian bookworm you get this correct output:
adding: msg.txt (stored 0%)
output of magic_file: application/zip
output of magic_buffer: application/zip
^^^^ it is application/zip in BOTH cases. That's good!
*/
#include <magic.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
int main()
{
unlink("msg.txt");
FILE *f = fopen("msg.txt", "w");
assert(f);
fprintf(f, "hello\n");
assert( ! ferror(f));
assert( ! fclose(f));
unlink("msg.x");
assert(system("zip -9 msg.x msg.txt") == 0); // don't name it .zip to show that this is not the problem here
magic_t m = magic_open(MAGIC_MIME_TYPE);
assert(m);
assert(magic_load(m, 0) == 0);
printf("output of magic_file: %s\n", magic_file(m, "msg.x"));
f = fopen("msg.x", "rb");
assert(f);
fseek(f, 0, SEEK_END);
size_t sz = ftell(f);
assert( ! ferror(f));
void *buf = malloc(sz);
rewind(f);
fread(buf, 1, sz, f);
assert( ! ferror(f));
assert(fclose(f) == 0);
printf("output of magic_buffer: %s\n", magic_buffer(m, buf, sz));
return 0;
}