"torchvision/csrc/cpu/deform_conv2d_kernel.cpp" did not exist on "cffac640d703196ea9a369166fa8ae587cb5e64d"
Commit cf5e25a9 authored by Juha Reunanen's avatar Juha Reunanen Committed by Davis E. King
Browse files

Problem: integer overflow when calculating sizes (may happen e.g. with very large images) (#1148)

* Problem: integer overflow when calculating sizes (may happen e.g. with very large images)
Solution: change some types from (unsigned) long to size_t

# Conflicts:
#	dlib/dnn/tensor.h

* Fix the fact that std::numeric_limits<unsigned long>::max() isn't always the same number

* Revert serialization changes

* Review fix: use long long instead of size_t

* From long to long long all the way

* Change more types to (hopefully) make the compiler happy

* Change many more types to size_t

* Change even more types to size_t

* Minor type changes
parent 1cf6dbf4
...@@ -100,7 +100,7 @@ namespace dlib ...@@ -100,7 +100,7 @@ namespace dlib
until clear() is called and succeeds until clear() is called and succeeds
!*/ !*/
unsigned long size ( size_t size (
) const; ) const;
/*! /*!
ensures ensures
......
...@@ -40,7 +40,7 @@ namespace dlib ...@@ -40,7 +40,7 @@ namespace dlib
typedef std::vector<neighbor>::const_iterator const_iterator; typedef std::vector<neighbor>::const_iterator const_iterator;
unsigned long size ( size_t size (
) const ) const
/*! /*!
ensures ensures
......
...@@ -91,7 +91,7 @@ namespace dlib ...@@ -91,7 +91,7 @@ namespace dlib
); );
// functions from the enumerable interface // functions from the enumerable interface
inline unsigned long size ( inline size_t size (
) const; ) const;
inline bool at_start ( inline bool at_start (
...@@ -311,7 +311,7 @@ namespace dlib ...@@ -311,7 +311,7 @@ namespace dlib
typename bst_base, typename bst_base,
typename mem_manager typename mem_manager
> >
unsigned long map_kernel_1<domain,range,bst_base,mem_manager>:: size_t map_kernel_1<domain,range,bst_base,mem_manager>::
size ( size (
) const ) const
{ {
......
...@@ -50,7 +50,7 @@ namespace dlib ...@@ -50,7 +50,7 @@ namespace dlib
cv_image() : _data(0), _widthStep(0), _nr(0), _nc(0) {} cv_image() : _data(0), _widthStep(0), _nr(0), _nc(0) {}
unsigned long size () const { return static_cast<unsigned long>(_nr*_nc); } size_t size () const { return static_cast<size_t>(_nr*_nc); }
inline pixel_type* operator[](const long row ) inline pixel_type* operator[](const long row )
{ {
......
...@@ -127,7 +127,7 @@ namespace dlib ...@@ -127,7 +127,7 @@ namespace dlib
- returns the number of columns in this image - returns the number of columns in this image
!*/ !*/
unsigned long size ( size_t size (
) const; ) const;
/*! /*!
ensures ensures
......
...@@ -66,7 +66,7 @@ namespace dlib ...@@ -66,7 +66,7 @@ namespace dlib
typedef T type; typedef T type;
explicit pipe ( explicit pipe (
unsigned long maximum_size size_t maximum_size
); );
virtual ~pipe ( virtual ~pipe (
...@@ -109,10 +109,10 @@ namespace dlib ...@@ -109,10 +109,10 @@ namespace dlib
bool is_enabled ( bool is_enabled (
) const; ) const;
unsigned long max_size ( size_t max_size (
) const; ) const;
unsigned long size ( size_t size (
) const; ) const;
bool enqueue ( bool enqueue (
...@@ -144,14 +144,14 @@ namespace dlib ...@@ -144,14 +144,14 @@ namespace dlib
private: private:
unsigned long pipe_size; size_t pipe_size;
const unsigned long pipe_max_size; const size_t pipe_max_size;
bool enabled; bool enabled;
T* const data; T* const data;
unsigned long first; size_t first;
unsigned long last; size_t last;
mutex m; mutex m;
signaler dequeue_sig; signaler dequeue_sig;
...@@ -181,7 +181,7 @@ namespace dlib ...@@ -181,7 +181,7 @@ namespace dlib
> >
pipe<T>:: pipe<T>::
pipe ( pipe (
unsigned long maximum_size size_t maximum_size
) : ) :
pipe_size(0), pipe_size(0),
pipe_max_size(maximum_size), pipe_max_size(maximum_size),
...@@ -313,7 +313,7 @@ namespace dlib ...@@ -313,7 +313,7 @@ namespace dlib
template < template <
typename T typename T
> >
unsigned long pipe<T>:: size_t pipe<T>::
max_size ( max_size (
) const ) const
{ {
...@@ -326,7 +326,7 @@ namespace dlib ...@@ -326,7 +326,7 @@ namespace dlib
template < template <
typename T typename T
> >
unsigned long pipe<T>:: size_t pipe<T>::
size ( size (
) const ) const
{ {
......
...@@ -38,7 +38,7 @@ namespace dlib ...@@ -38,7 +38,7 @@ namespace dlib
typedef T type; typedef T type;
explicit pipe ( explicit pipe (
unsigned long maximum_size size_t maximum_size
); );
/*! /*!
ensures ensures
...@@ -175,7 +175,7 @@ namespace dlib ...@@ -175,7 +175,7 @@ namespace dlib
- #is_dequeue_enabled() == true - #is_dequeue_enabled() == true
!*/ !*/
unsigned long max_size ( size_t max_size (
) const; ) const;
/*! /*!
ensures ensures
...@@ -183,7 +183,7 @@ namespace dlib ...@@ -183,7 +183,7 @@ namespace dlib
pipe can contain. pipe can contain.
!*/ !*/
unsigned long size ( size_t size (
) const; ) const;
/*! /*!
ensures ensures
......
...@@ -103,7 +103,7 @@ namespace dlib ...@@ -103,7 +103,7 @@ namespace dlib
); );
// functions from the enumerable interface // functions from the enumerable interface
inline unsigned long size ( inline size_t size (
) const; ) const;
inline bool at_start ( inline bool at_start (
...@@ -402,7 +402,7 @@ namespace dlib ...@@ -402,7 +402,7 @@ namespace dlib
typename T, typename T,
typename mem_manager typename mem_manager
> >
unsigned long queue_kernel_1<T,mem_manager>:: size_t queue_kernel_1<T,mem_manager>::
size ( size (
) const ) const
{ {
......
...@@ -112,7 +112,7 @@ namespace dlib ...@@ -112,7 +112,7 @@ namespace dlib
); );
// functions from the enumerable interface // functions from the enumerable interface
inline unsigned long size ( inline size_t size (
) const; ) const;
inline bool at_start ( inline bool at_start (
...@@ -155,13 +155,13 @@ namespace dlib ...@@ -155,13 +155,13 @@ namespace dlib
node* in; node* in;
node* out; node* out;
unsigned long queue_size; size_t queue_size;
unsigned long in_pos; size_t in_pos;
unsigned long out_pos; size_t out_pos;
mutable node* current_element; mutable node* current_element;
mutable unsigned long current_element_pos; mutable size_t current_element_pos;
mutable bool at_start_; mutable bool at_start_;
// restricted functions // restricted functions
...@@ -419,7 +419,7 @@ namespace dlib ...@@ -419,7 +419,7 @@ namespace dlib
unsigned long block_size, unsigned long block_size,
typename mem_manager typename mem_manager
> >
unsigned long queue_kernel_2<T,block_size,mem_manager>:: size_t queue_kernel_2<T,block_size,mem_manager>::
size ( size (
) const ) const
{ {
......
...@@ -144,7 +144,7 @@ namespace dlib ...@@ -144,7 +144,7 @@ namespace dlib
); );
// functions from the enumerable interface // functions from the enumerable interface
inline unsigned long size ( inline size_t size (
) const; ) const;
bool at_start ( bool at_start (
...@@ -446,7 +446,7 @@ namespace dlib ...@@ -446,7 +446,7 @@ namespace dlib
typename T, typename T,
typename mem_manager typename mem_manager
> >
unsigned long sequence_kernel_1<T,mem_manager>:: size_t sequence_kernel_1<T,mem_manager>::
size ( size (
) const ) const
{ {
......
...@@ -103,7 +103,7 @@ namespace dlib ...@@ -103,7 +103,7 @@ namespace dlib
); );
// functions from the enumerable interface // functions from the enumerable interface
inline unsigned long size ( inline size_t size (
) const; ) const;
bool at_start ( bool at_start (
...@@ -430,7 +430,7 @@ namespace dlib ...@@ -430,7 +430,7 @@ namespace dlib
typename T, typename T,
typename mem_manager typename mem_manager
> >
unsigned long sequence_kernel_2<T,mem_manager>:: size_t sequence_kernel_2<T,mem_manager>::
size ( size (
) const ) const
{ {
......
...@@ -80,7 +80,7 @@ namespace dlib ...@@ -80,7 +80,7 @@ namespace dlib
); );
// functions from the enumerable interface // functions from the enumerable interface
inline unsigned long size ( inline size_t size (
) const; ) const;
inline bool at_start ( inline bool at_start (
...@@ -254,7 +254,7 @@ namespace dlib ...@@ -254,7 +254,7 @@ namespace dlib
typename bst_base, typename bst_base,
typename mem_manager typename mem_manager
> >
unsigned long set_kernel_1<T,bst_base,mem_manager>:: size_t set_kernel_1<T,bst_base,mem_manager>::
size ( size (
) const ) const
{ {
......
...@@ -82,7 +82,7 @@ namespace dlib ...@@ -82,7 +82,7 @@ namespace dlib
catch (...) { buffer = 0; buffer_size = 0; throw; } catch (...) { buffer = 0; buffer_size = 0; throw; }
} }
unsigned long size ( size_t size (
) const { return buffer_size; } ) const { return buffer_size; }
void rotate_left ( void rotate_left (
......
...@@ -97,7 +97,7 @@ namespace dlib ...@@ -97,7 +97,7 @@ namespace dlib
); );
// functions from the enumerable interface // functions from the enumerable interface
inline unsigned long size ( inline size_t size (
) const; ) const;
inline bool at_start ( inline bool at_start (
...@@ -365,7 +365,7 @@ namespace dlib ...@@ -365,7 +365,7 @@ namespace dlib
typename T, typename T,
typename mem_manager typename mem_manager
> >
unsigned long stack_kernel_1<T,mem_manager>:: size_t stack_kernel_1<T,mem_manager>::
size ( size (
) const ) const
{ {
......
...@@ -157,7 +157,7 @@ namespace dlib ...@@ -157,7 +157,7 @@ namespace dlib
); );
// functions from the enumerable interface // functions from the enumerable interface
inline unsigned long size ( inline size_t size (
) const; ) const;
inline bool at_start ( inline bool at_start (
...@@ -433,7 +433,7 @@ namespace dlib ...@@ -433,7 +433,7 @@ namespace dlib
typename range, typename range,
typename compare typename compare
> >
unsigned long static_map_kernel_1<domain,range,compare>:: size_t static_map_kernel_1<domain,range,compare>::
size ( size (
) const ) const
{ {
......
...@@ -52,11 +52,11 @@ namespace dlib ...@@ -52,11 +52,11 @@ namespace dlib
try try
{ {
item.clear(); item.clear();
unsigned long size; size_t size;
deserialize(size,in); deserialize(size,in);
item.set_size = size; item.set_size = size;
item.d = new T[size]; item.d = new T[size];
for (unsigned long i = 0; i < size; ++i) for (size_t i = 0; i < size; ++i)
{ {
deserialize(item.d[i],in); deserialize(item.d[i],in);
} }
...@@ -116,7 +116,7 @@ namespace dlib ...@@ -116,7 +116,7 @@ namespace dlib
); );
// functions from the enumerable interface // functions from the enumerable interface
inline unsigned long size ( inline size_t size (
) const; ) const;
inline bool at_start ( inline bool at_start (
...@@ -142,7 +142,7 @@ namespace dlib ...@@ -142,7 +142,7 @@ namespace dlib
// data members // data members
unsigned long set_size; size_t set_size;
T* d; T* d;
mutable T* cur; mutable T* cur;
mutable bool at_start_; mutable bool at_start_;
...@@ -231,7 +231,7 @@ namespace dlib ...@@ -231,7 +231,7 @@ namespace dlib
set_size = source.size(); set_size = source.size();
for (unsigned long i = 0; source.size() > 0; ++i) for (size_t i = 0; source.size() > 0; ++i)
source.remove_any(d[i]); source.remove_any(d[i]);
compare comp; compare comp;
...@@ -261,7 +261,7 @@ namespace dlib ...@@ -261,7 +261,7 @@ namespace dlib
set_size = source.size(); set_size = source.size();
for (unsigned long i = 0; source.size() > 0; ++i) for (size_t i = 0; source.size() > 0; ++i)
source.remove_any(d[i]); source.remove_any(d[i]);
} }
else else
...@@ -282,10 +282,10 @@ namespace dlib ...@@ -282,10 +282,10 @@ namespace dlib
const T& item const T& item
) const ) const
{ {
unsigned long high = set_size; size_t high = set_size;
unsigned long low = 0; size_t low = 0;
unsigned long p = set_size; size_t p = set_size;
unsigned long idx; size_t idx;
while (p > 0) while (p > 0)
{ {
p = (high-low)>>1; p = (high-low)>>1;
...@@ -306,7 +306,7 @@ namespace dlib ...@@ -306,7 +306,7 @@ namespace dlib
typename T, typename T,
typename compare typename compare
> >
unsigned long static_set_kernel_1<T,compare>:: size_t static_set_kernel_1<T,compare>::
size ( size (
) const ) const
{ {
...@@ -421,7 +421,7 @@ namespace dlib ...@@ -421,7 +421,7 @@ namespace dlib
else if (cur != 0) else if (cur != 0)
{ {
++cur; ++cur;
if (static_cast<unsigned long>(cur - d) < set_size) if (static_cast<size_t>(cur - d) < set_size)
{ {
return true; return true;
} }
......
...@@ -67,7 +67,7 @@ namespace dlib ...@@ -67,7 +67,7 @@ namespace dlib
const std::vector<T>& to_std_vector( const std::vector<T>& to_std_vector(
) const { return items; } ) const { return items; }
unsigned long size ( size_t size (
) const ) const
{ {
return items.size(); return items.size();
......
...@@ -101,7 +101,7 @@ namespace dlib ...@@ -101,7 +101,7 @@ namespace dlib
- #size() == 0 - #size() == 0
!*/ !*/
unsigned long size ( size_t size (
) const; ) const;
/*! /*!
ensures ensures
......
...@@ -65,7 +65,7 @@ namespace dlib ...@@ -65,7 +65,7 @@ namespace dlib
} }
template <typename kernel_type> template <typename kernel_type>
inline unsigned long size ( inline size_t size (
const typename kernel_type::sample_type& const typename kernel_type::sample_type&
) )
{ {
......
...@@ -296,7 +296,7 @@ namespace dlib ...@@ -296,7 +296,7 @@ namespace dlib
temp.swap(item.temp); temp.swap(item.temp);
} }
unsigned long size ( size_t size (
) const { return dictionary.size(); } ) const { return dictionary.size(); }
const matrix<sample_type,0,1,mem_manager_type> get_dictionary ( const matrix<sample_type,0,1,mem_manager_type> get_dictionary (
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment