Comments (7)
I believe the problem is within lfnGetName(), when the filename stored on the FAT volume has a null terminating char.
static size_t lfnGetName(DirLfn_t* ldir, char* name, size_t n) {
uint8_t i;
size_t k = 13*((ldir->order & 0X1F) - 1);
for (i = 0; i < 13; i++) {
uint16_t c = lfnGetChar(ldir, i);
if (c == 0 || k >= (n - 1)) {
k = n - 1;
break;
}
name[k++] = c >= 0X7F ? '?' : c;
}
// Terminate with zero byte.
name[k] = '\0';
return k;
}
Inside the loop, when lfnGetChar() returns zero, k is set to n - 1, which causes the null terminating zero to be written at the end of the user's buffer for the case of short string. The c == 0 case should probably break from the loop without altering k, so the null terminating zero is written at the correct location.
if (c == 0) break; // do not alter k for this case, so the zero termination is written at correct location
if (k >= (n - 1)) {
k = n - 1;
break;
}
from sdfat-beta.
Or maybe k should be checked first? I'm not sure if the initial compute of k could be too large, or if that's a non-issue?
from sdfat-beta.
I need to rethink how getName works. I suspect there is more than one bug. I think I produced a new bug trying to fix another bug.
Long file names are stored like this in the directory. So I am backing though the directory file.
Nth Long entry with flag LAST_LONG_ENTRY (0x40)
… Additional Long Entries …
1st Long entry 1
Short Entry Associated With Preceding Long Entries
from sdfat-beta.
I haven't noticed any other problem.
from sdfat-beta.
I verified the bug and the following seems to fix it. I would appreciate if you tested any case you have.
static size_t lfnGetName(DirLfn_t* ldir, char* name, size_t n) {
uint8_t i;
size_t k = 13*((ldir->order & 0X1F) - 1);
for (i = 0; i < 13; i++) {
uint16_t c = lfnGetChar(ldir, i);
if (c == 0 || k >= (n - 1)) {
// k = n - 1; <<-------removed
break;
}
name[k++] = c >= 0X7F ? '?' : c;
}
// Terminate with zero byte.
if (k >= n) { // <<----------added
k = n - 1; // <<--------- added
} // <<---------added
name[k] = '\0';
return k;
}
from sdfat-beta.
Yes, confirmed, that works great.
I tested here by reverting to the original code and checking that the problem did indeed return (turns out not all boards & programs reproduce the problem - many cases default to buffers pre-filled with zeros), and then I put this into FatFileLFN.cpp and it definitely does solve the problem.
from sdfat-beta.
Thank for the check. I will post a new beta today.
The bss zeroed array caught me with a quick fix for another case. I now have a sketch that makes all filename lengths, fills the buffer with '?' before each call and uses a series of buffer lengths to verify truncation.
from sdfat-beta.
Related Issues (20)
- hosting the documentation on a github.io page HOT 2
- SD card error with beta version HOT 7
- .h files in separate directories not found HOT 1
- PlatformIO compatibility HOT 1
- ESP32, Multiple cards, and Software Serial questions HOT 13
- SPI access to external SD Card other than normal SPI Pins (not soft spi) HOT 10
- Moving cursor position with O_APPEND HOT 1
- Support for Multiple Partitions HOT 2
- FsVolume support partition? Also maybe memory leaks HOT 9
- Maybe support __has_include for configuration for sketch or library override of configuration. HOT 5
- Warning "'next' may be used uninitialized in this function" HOT 3
- Conflict between SdFat-beta library and USBFat library
- cannot open File with UTF-8 Name HOT 1
- Any attempt to have Web SD file Downloader
- ESP32 check sd format HOT 6
- SD Card hot swap HOT 1
- 'SdFat {aka class SdFs}' has no member named 'vwd' HOT 7
- SDIO multi-sector read timings HOT 2
- Some SDCard Samples work others not ,SdFat Lib 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 sdfat-beta.