Skip to content

fix(output): use >= when guarding feature vector capacity - #1733

Open
antonkesy wants to merge 1 commit into
Netflix:masterfrom
antonkesy:fix/output-capacity-oob
Open

antonkesy wants to merge 1 commit into
Netflix:masterfrom
antonkesy:fix/output-capacity-oob

Conversation

@antonkesy

@antonkesy antonkesy commented Nov 20, 2026 •

Copy link
Copy Markdown

The guard i > capacity let i == capacity through, reading score[capacity] one element past the allocation in the XML, JSON, CSV and SUB writers.

Reproduces with small program and AdressSanitizer:

#include <stdio.h>
#include "feature/feature_collector.h"
#include "output.h"
int main(void) {
    VmafFeatureCollector *fc;
    vmaf_feature_collector_init(&fc);
    vmaf_feature_collector_append(fc, "a", 1.0, 0);  /* capacity 8  */
    vmaf_feature_collector_append(fc, "b", 2.0, 9);  /* capacity 16 */
    FILE *f = fopen("/dev/null", "w");
    int r = vmaf_write_output_csv(fc, f, 0);
    fclose(f);
    vmaf_feature_collector_destroy(fc);
    printf("ret=%d\n", r);
    return 0;
}
==1749416==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x76daccde0180 at pc 0x64d08c56f87a bp 0x7ffc6e26e850 sp 0x7ffc6e26e840                     
READ of size 1 at 0x76daccde0180 thread 
    #0 0x64d08c56f879 in vmaf_write_output_csv (...) (BuildId: 547725035c971fed00402d9b59e33c2ee1705f8c
    #1 0x64d08c568806 in main /home/.../out.c:7
    #2 0x7a1acda2a600  (/usr/lib/x86_64-linux-gnu/libc.so.6+0x2a600) (BuildId: 851d79b1f32e900a27f8d0a68e29d750303f0c6)                                            
    #3 0x7a1acda2a717 in __libc_start_main (/usr/lib/x86_64-linux-gnu/libc.so.6+0x2a717) (BuildId: 9851d79b1f32e900a27f8d0a68e29d750303f0c6)
    #4 0x64d08c5685c4 in _start (/home/ak/.../out_test+0x185c4) (BuildId: 547725035c971fed00402d9b59e33c2ee1705f8c)

0x76daccde0180 is located 0 bytes after 128-byte region [0x76daccde0100,0x76daccde0180)
allocated by thread T0 here:
    #0 0x7a1ace32b40f in calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:74
    #1 0x64d08c56a00c in vmaf_feature_collector_append (/home/ak/.../out_test+0x1a00c) (BuildId: 547725035c971fed00402d9b59e33c2ee1705f8c)
    #2 0x64d08c568761 in main /home/ak/.../out.c:5
    #3 0x7a1acda2a600  (/usr/lib/x86_64-linux-gnu/libc.so.6+0x2a600) (BuildId: 9851d79b1f32e900a27f8d0a68e29d750303f0c6)
    #4 0x7a1acda2a717 in __libc_start_main (/usr/lib/x86_64-linux-gnu/libc.so.6+0x2a717) (BuildId: 9851d79b1f32e900a27f8d0a68e29d750303f0c6)
    #5 0x64d08c5685c4 in _start (/home/ak/.../out_test+0x185c4) (BuildId: 547725035c971fed00402d9b59e33c2ee1705f8c)

The guard 'i > capacity' let i == capacity through, reading
score[capacity] one element past the allocation in the XML, JSON, CSV
and SUB writers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant