Bug 42080: (follow-up) limit data sent to libmagic to 100 characters

By limiting the data sent to libmagic to 100 characters, we make
the test faster and we avoid situations where a large or malicious
file causes too many resources to be used.

100 characters is more than enough for the file types we're allowing.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
David Cook 2026-03-16 00:05:45 +00:00 committed by Pedro Amorim
parent 1c6328b82b
commit 9a39e4799a
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
1 changed files with 2 additions and 1 deletions

View File

@ -74,7 +74,8 @@ if ( $op eq 'download' ) {
my $ftype = $file->{'file_type'};
my $magic = File::LibMagic->new();
my $magic_info = $magic->info_from_string( $file->{'file_content'} );
my $test_str = substr( $file->{'file_content'}, 0, 99 );
my $magic_info = $magic->info_from_string( \$test_str );
my $magic_mime_type = $magic_info->{mime_type};
if ( $input->param('view') && ( $magic_mime_type && $allowed_ftypes->{$magic_mime_type} ) ) {
print $input->header(