xen / darts-clone Goto Github PK
View Code? Open in Web Editor NEWAutomatically exported from code.google.com/p/darts-clone
License: BSD 3-Clause "New" or "Revised" License
Automatically exported from code.google.com/p/darts-clone
License: BSD 3-Clause "New" or "Revised" License
RT
Original issue reported on code.google.com by [email protected]
on 13 Oct 2014 at 3:17
template <typename A, typename B, typename T, typename C>
int DoubleArrayImpl<A, B, T, C>::save(const char *file_name,
const char *mode, std::size_t offset) const {
if (size() == 0) {
return -1;
}
#ifdef _MSC_VER
std::FILE *file;
if (::fopen_s(&file, file_name, mode) != 0) {
return -1;
}
#else
std::FILE *file = std::fopen(file_name, mode);
if (file == NULL) {
return -1;
}
#endif
// you should add fseek
if (std::fseek(file, offset, SEEK_SET) != 0) {
std::fclose(file);
return -1;
}
if (std::fwrite(array_, unit_size(), size(), file) != size()) {
std::fclose(file);
return -1;
}
std::fclose(file);
return 0;
}
Original issue reported on code.google.com by [email protected]
on 26 Nov 2013 at 2:11
What steps will reproduce the problem?
A. darts-clone is crashed after read a illegal binary file.
What is the expected output? What do you see instead?
A. make sure the file is safe before loading it,and exit when the binary file
is illegal.
What version of the product are you using? On what operating system?
A.
version:0.32
os:Red Hat Enterprise Linux AS release 4
gcc:gcc version 4.4.4 20100726
Please provide any additional information below.
1. example:
//some modified
template <typename A, typename B, typename T, typename C>
int DoubleArrayImpl<A, B, T, C>::save(const char *file_name,
const char *mode, std::size_t) const {
if (size() == 0) {
return -1;
}
#ifdef _MSC_VER
std::FILE *file;
if (::fopen_s(&file, file_name, mode) != 0) {
return -1;
}
#else
std::FILE *file = std::fopen(file_name, mode);
if (file == NULL) {
return -1;
}
#endif
int a = size();
if(std::fwrite(&a, sizeof(int), 1, file) != 1)
{
std::fclose(file);
return -1;
}
if (std::fwrite(array_, unit_size(), size(), file) != size()) {
std::fclose(file);
return -1;
}
std::fclose(file);
return 0;
}
template <typename A, typename B, typename T, typename C>
int DoubleArrayImpl<A, B, T, C>::open(const char *file_name,
const char *mode, std::size_t offset, std::size_t size) {
#ifdef _MSC_VER
std::FILE *file;
if (::fopen_s(&file, file_name, mode) != 0) {
return -1;
}
#else
std::FILE *file = std::fopen(file_name, mode);
if (file == NULL) {
return -1;
}
#endif
//check 1
int a = 0;
if(std::fread(&a, sizeof(int), 1, file) != 1)
{
std::fclose(file);
return -1;
}
if (size == 0) {
if (std::fseek(file, 0, SEEK_END) != 0) {
std::fclose(file);
return -1;
}
size = std::ftell(file) - sizeof(int) - offset;
}
//plus sizeof(int)
if (std::fseek(file, offset+sizeof(int), SEEK_SET) != 0) {
std::fclose(file);
return -1;
}
size /= unit_size();
//check 2
if(size != (unsigned)a)
{
std::fclose(file);
return -1;
}
unit_type *buf= NULL;
buf = new (std::nothrow) unit_type[size];
if(buf == NULL) {
std::fclose(file);
//fprintf(stderr, "faile to open\n");
DARTS_THROW("failed to open double-array: std::bad_alloc");
return -1;
}
if (std::fread(buf, unit_size(), size, file) != size) {
std::fclose(file);
delete[] buf;
return -1;
}
std::fclose(file);
clear();
size_ = size;
array_ = buf;
buf_ = buf;
return 0;
}
Original issue reported on code.google.com by [email protected]
on 10 Dec 2012 at 7:15
What steps will reproduce the problem?
i can't understand why the second param is 3。
if i change DoubleArrayBase<int,3> to DoubleArrayBase<short,3>,is the second
param
still is 3 will be ok?
Original issue reported on code.google.com by [email protected]
on 10 Jun 2014 at 11:51
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.