1 // Copyright 2019 The PDFium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "testing/test_loader.h" 6 7 #include <stddef.h> 8 9 #include "core/fxcrt/check_op.h" 10 #include "core/fxcrt/fx_memcpy_wrappers.h" 11 #include "core/fxcrt/numerics/checked_math.h" 12 TestLoader(pdfium::span<const uint8_t> span)13TestLoader::TestLoader(pdfium::span<const uint8_t> span) : m_Span(span) {} 14 15 // static GetBlock(void * param,unsigned long pos,unsigned char * pBuf,unsigned long size)16int TestLoader::GetBlock(void* param, 17 unsigned long pos, 18 unsigned char* pBuf, 19 unsigned long size) { 20 TestLoader* pLoader = static_cast<TestLoader*>(param); 21 pdfium::CheckedNumeric<size_t> end = pos; 22 end += size; 23 CHECK_LE(end.ValueOrDie(), pLoader->m_Span.size()); 24 25 FXSYS_memcpy(pBuf, &pLoader->m_Span[pos], size); 26 return 1; 27 } 28