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 <string.h> 8 9 #include "third_party/base/check_op.h" 10 #include "third_party/base/numerics/checked_math.h" 11 TestLoader(pdfium::span<const char> span)12TestLoader::TestLoader(pdfium::span<const char> span) : m_Span(span) {} 13 14 // static GetBlock(void * param,unsigned long pos,unsigned char * pBuf,unsigned long size)15int TestLoader::GetBlock(void* param, 16 unsigned long pos, 17 unsigned char* pBuf, 18 unsigned long size) { 19 TestLoader* pLoader = static_cast<TestLoader*>(param); 20 pdfium::base::CheckedNumeric<size_t> end = pos; 21 end += size; 22 CHECK_LE(end.ValueOrDie(), pLoader->m_Span.size()); 23 24 memcpy(pBuf, &pLoader->m_Span[pos], size); 25 return 1; 26 } 27