Comments (5)
For checking it and getting file size you can use something like this:
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int get_file_size(const char* filename, size_t& out_result) {
struct stat st;
if(stat(filename, &st) != 0) {
// return error
}
if (!S_ISREG(st.st_mode)) {
// return error
}
out_result = st.st_size;
// return ok
}
Or use Filesystem library (since C++17) for getting size: std::filesystem::path
with std::filesystem::file_size
In case of using it with dirs it throws exception:
terminate called after throwing an instance of 'std::filesystem::__cxx11::filesystem_error'
what(): filesystem error: cannot get file size: Is a directory [/]
from pugixml.
The bug was found with Futag
from pugixml.
Thanks! This should not have production impact, as the code correctly handles the OOM, but is certainly inconvenient for fuzzing. ftell here returns the maximum signed integer of the relevant type instead of returning a negative number for some reason.
std::filesystem can't be used in pugixml as it doesn't use STL except for STL-specific API helpers that can be disabled, and carries compatibility burden on systems like macOS. It is probably better to solve this by explicitly checking the size; stat could work but has some other issues and an extra syscall per file open is not optimal for some workloads. That said, maybe stat is actually fine; I'll look into this further.
from pugixml.
Ah, looks like I hit this before :) 7664bbf
from pugixml.
Looks like fseek/ftell use fstatat under the hood, so stat is actually more efficient (only matters for small files, but right now it takes us 7 syscalls to read a file, and with stat it only takes 5; one of these is done by fread and can be removed by switching to open/read or by disabling buffering via setvbuf).
from pugixml.
Related Issues (20)
- Empty text childs increase XML file size HOT 5
- xml_node_iterator should satisfy at least std::input_or_output_iterator concept HOT 3
- Assertion fails during number-to-string conversion if wrong C locale is set (non-MSVC) HOT 1
- Support std::filesystem::path HOT 2
- Version 1.14 HOT 1
- Can you add the ability to access child nodes using index? HOT 1
- PUGIXML_WCHAR_MODE and error messages. HOT 1
- add xml_node_type_str function for debugging and application logging HOT 3
- option to join multiple CDATA sections into one when parsing HOT 2
- parse_embed_pcdata and parse_merge_pcdata don't play together HOT 2
- Unexpected #endif in line 13201 with precompilation in a pch.h file HOT 2
- XML Canonicalization: as an option, allow parsing eol's into the document model (as PCDATA holding those) HOT 2
- Warning when building 1.14 in x86 on Clang HOT 3
- Position of the parse result offset in case of status_bad_start_element
- Error in handling loading errors example HOT 1
- Incorrect result of xml_document::load_file -"File was not found" HOT 2
- Question: I have made my own case insensitive version, is that ok? HOT 2
- Serilisation HOT 4
- pugi::xml_node and std::ranges, maybe a documentation request HOT 2
- call function xml_node::empty() always return false in anyway HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pugixml.