mirror of
https://github.com/littlefs-project/littlefs.git
synced 2025-11-16 12:34:34 +00:00
Compare commits
8 Commits
v2.9.3
...
fix-seek-o
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
abaec45652 | ||
|
|
f1c430e779 | ||
|
|
b78afe2518 | ||
|
|
798073c2a7 | ||
|
|
7db9e1663a | ||
|
|
2c4b262c35 | ||
|
|
72a4b57f4e | ||
|
|
6e7269890a |
29
.github/workflows/release.yml
vendored
29
.github/workflows/release.yml
vendored
@@ -20,7 +20,7 @@ jobs:
|
|||||||
github.event.workflow_run.head_sha == github.sha}}
|
github.event.workflow_run.head_sha == github.sha}}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
ref: ${{github.event.workflow_run.head_sha}}
|
ref: ${{github.event.workflow_run.head_sha}}
|
||||||
# need workflow access since we push branches
|
# need workflow access since we push branches
|
||||||
@@ -30,26 +30,29 @@ jobs:
|
|||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
# try to get results from tests
|
# try to get results from tests
|
||||||
- uses: dawidd6/action-download-artifact@v2
|
- uses: actions/download-artifact@v4
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
with:
|
with:
|
||||||
workflow: ${{github.event.workflow_run.name}}
|
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||||
run_id: ${{github.event.workflow_run.id}}
|
run-id: ${{github.event.workflow_run.id}}
|
||||||
name: sizes
|
pattern: '{sizes,sizes-*}'
|
||||||
|
merge-multiple: true
|
||||||
path: sizes
|
path: sizes
|
||||||
- uses: dawidd6/action-download-artifact@v2
|
- uses: actions/download-artifact@v4
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
with:
|
with:
|
||||||
workflow: ${{github.event.workflow_run.name}}
|
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||||
run_id: ${{github.event.workflow_run.id}}
|
run-id: ${{github.event.workflow_run.id}}
|
||||||
name: cov
|
pattern: '{cov,cov-*}'
|
||||||
|
merge-multiple: true
|
||||||
path: cov
|
path: cov
|
||||||
- uses: dawidd6/action-download-artifact@v2
|
- uses: actions/download-artifact@v4
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
with:
|
with:
|
||||||
workflow: ${{github.event.workflow_run.name}}
|
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||||
run_id: ${{github.event.workflow_run.id}}
|
run-id: ${{github.event.workflow_run.id}}
|
||||||
name: bench
|
pattern: '{bench,bench-*}'
|
||||||
|
merge-multiple: true
|
||||||
path: bench
|
path: bench
|
||||||
|
|
||||||
- name: find-version
|
- name: find-version
|
||||||
|
|||||||
18
.github/workflows/status.yml
vendored
18
.github/workflows/status.yml
vendored
@@ -13,12 +13,13 @@ jobs:
|
|||||||
status:
|
status:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: dawidd6/action-download-artifact@v2
|
- uses: actions/download-artifact@v4
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
with:
|
with:
|
||||||
workflow: ${{github.event.workflow_run.name}}
|
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||||
run_id: ${{github.event.workflow_run.id}}
|
run-id: ${{github.event.workflow_run.id}}
|
||||||
name: status
|
pattern: '{status,status-*}'
|
||||||
|
merge-multiple: true
|
||||||
path: status
|
path: status
|
||||||
- name: update-status
|
- name: update-status
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
@@ -67,12 +68,13 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
# generated comment?
|
# generated comment?
|
||||||
- uses: dawidd6/action-download-artifact@v2
|
- uses: actions/download-artifact@v4
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
with:
|
with:
|
||||||
workflow: ${{github.event.workflow_run.name}}
|
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||||
run_id: ${{github.event.workflow_run.id}}
|
run-id: ${{github.event.workflow_run.id}}
|
||||||
name: comment
|
pattern: '{comment,comment-*}'
|
||||||
|
merge-multiple: true
|
||||||
path: comment
|
path: comment
|
||||||
- name: update-comment
|
- name: update-comment
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|||||||
72
.github/workflows/test.yml
vendored
72
.github/workflows/test.yml
vendored
@@ -21,7 +21,7 @@ jobs:
|
|||||||
arch: [x86_64, thumb, mips, powerpc]
|
arch: [x86_64, thumb, mips, powerpc]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
- name: install
|
- name: install
|
||||||
run: |
|
run: |
|
||||||
# need a few things
|
# need a few things
|
||||||
@@ -235,9 +235,9 @@ jobs:
|
|||||||
|
|
||||||
# create size statuses
|
# create size statuses
|
||||||
- name: upload-sizes
|
- name: upload-sizes
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: sizes
|
name: sizes-${{matrix.arch}}
|
||||||
path: sizes
|
path: sizes
|
||||||
- name: status-sizes
|
- name: status-sizes
|
||||||
run: |
|
run: |
|
||||||
@@ -273,16 +273,17 @@ jobs:
|
|||||||
}' | tee status/$(basename $f .csv).json
|
}' | tee status/$(basename $f .csv).json
|
||||||
done
|
done
|
||||||
- name: upload-status-sizes
|
- name: upload-status-sizes
|
||||||
uses: actions/upload-artifact@v2
|
if: ${{matrix.arch == 'x86_64'}}
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: status
|
name: status-sizes-${{matrix.arch}}
|
||||||
path: status
|
path: status
|
||||||
retention-days: 1
|
retention-days: 1
|
||||||
|
|
||||||
# create cov statuses
|
# create cov statuses
|
||||||
- name: upload-cov
|
- name: upload-cov
|
||||||
if: ${{matrix.arch == 'x86_64'}}
|
if: ${{matrix.arch == 'x86_64'}}
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: cov
|
name: cov
|
||||||
path: cov
|
path: cov
|
||||||
@@ -317,11 +318,11 @@ jobs:
|
|||||||
target_step: env.STEP,
|
target_step: env.STEP,
|
||||||
}' | tee status/$(basename $f .csv)-$s.json
|
}' | tee status/$(basename $f .csv)-$s.json
|
||||||
done
|
done
|
||||||
- name: upload-status-sizes
|
- name: upload-status-cov
|
||||||
if: ${{matrix.arch == 'x86_64'}}
|
if: ${{matrix.arch == 'x86_64'}}
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: status
|
name: status-cov
|
||||||
path: status
|
path: status
|
||||||
retention-days: 1
|
retention-days: 1
|
||||||
|
|
||||||
@@ -336,7 +337,7 @@ jobs:
|
|||||||
pls: [1, 2]
|
pls: [1, 2]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
- name: install
|
- name: install
|
||||||
run: |
|
run: |
|
||||||
# need a few things
|
# need a few things
|
||||||
@@ -361,7 +362,7 @@ jobs:
|
|||||||
test-no-intrinsics:
|
test-no-intrinsics:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
- name: install
|
- name: install
|
||||||
run: |
|
run: |
|
||||||
# need a few things
|
# need a few things
|
||||||
@@ -378,7 +379,7 @@ jobs:
|
|||||||
test-multiversion:
|
test-multiversion:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
- name: install
|
- name: install
|
||||||
run: |
|
run: |
|
||||||
# need a few things
|
# need a few things
|
||||||
@@ -395,7 +396,7 @@ jobs:
|
|||||||
test-lfs2_0:
|
test-lfs2_0:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
- name: install
|
- name: install
|
||||||
run: |
|
run: |
|
||||||
# need a few things
|
# need a few things
|
||||||
@@ -414,7 +415,7 @@ jobs:
|
|||||||
test-valgrind:
|
test-valgrind:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
- name: install
|
- name: install
|
||||||
run: |
|
run: |
|
||||||
# need a few things
|
# need a few things
|
||||||
@@ -436,7 +437,7 @@ jobs:
|
|||||||
test-clang:
|
test-clang:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
- name: install
|
- name: install
|
||||||
run: |
|
run: |
|
||||||
# need a few things
|
# need a few things
|
||||||
@@ -459,7 +460,7 @@ jobs:
|
|||||||
bench:
|
bench:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
- name: install
|
- name: install
|
||||||
run: |
|
run: |
|
||||||
# need a few things
|
# need a few things
|
||||||
@@ -491,7 +492,7 @@ jobs:
|
|||||||
|
|
||||||
# create bench statuses
|
# create bench statuses
|
||||||
- name: upload-bench
|
- name: upload-bench
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: bench
|
name: bench
|
||||||
path: bench
|
path: bench
|
||||||
@@ -525,9 +526,9 @@ jobs:
|
|||||||
}' | tee status/$(basename $f .csv)-$s.json
|
}' | tee status/$(basename $f .csv)-$s.json
|
||||||
done
|
done
|
||||||
- name: upload-status-bench
|
- name: upload-status-bench
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: status
|
name: status-bench
|
||||||
path: status
|
path: status
|
||||||
retention-days: 1
|
retention-days: 1
|
||||||
|
|
||||||
@@ -535,10 +536,10 @@ jobs:
|
|||||||
test-compat:
|
test-compat:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
if: ${{github.event_name == 'pull_request'}}
|
if: ${{github.event_name == 'pull_request'}}
|
||||||
# checkout the current pr target into lfsp
|
# checkout the current pr target into lfsp
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
if: ${{github.event_name == 'pull_request'}}
|
if: ${{github.event_name == 'pull_request'}}
|
||||||
with:
|
with:
|
||||||
ref: ${{github.event.pull_request.base.ref}}
|
ref: ${{github.event.pull_request.base.ref}}
|
||||||
@@ -572,7 +573,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: ${{!endsWith(github.ref, '-prefix')}}
|
if: ${{!endsWith(github.ref, '-prefix')}}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
- name: install
|
- name: install
|
||||||
run: |
|
run: |
|
||||||
# need a few things
|
# need a few things
|
||||||
@@ -582,7 +583,7 @@ jobs:
|
|||||||
gcc --version
|
gcc --version
|
||||||
python3 --version
|
python3 --version
|
||||||
fusermount -V
|
fusermount -V
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
repository: littlefs-project/littlefs-fuse
|
repository: littlefs-project/littlefs-fuse
|
||||||
ref: v2
|
ref: v2
|
||||||
@@ -622,7 +623,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: ${{!endsWith(github.ref, '-prefix')}}
|
if: ${{!endsWith(github.ref, '-prefix')}}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
- name: install
|
- name: install
|
||||||
run: |
|
run: |
|
||||||
# need a few things
|
# need a few things
|
||||||
@@ -632,12 +633,12 @@ jobs:
|
|||||||
gcc --version
|
gcc --version
|
||||||
python3 --version
|
python3 --version
|
||||||
fusermount -V
|
fusermount -V
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
repository: littlefs-project/littlefs-fuse
|
repository: littlefs-project/littlefs-fuse
|
||||||
ref: v2
|
ref: v2
|
||||||
path: v2
|
path: v2
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
repository: littlefs-project/littlefs-fuse
|
repository: littlefs-project/littlefs-fuse
|
||||||
ref: v1
|
ref: v1
|
||||||
@@ -694,7 +695,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [test, bench]
|
needs: [test, bench]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v4
|
||||||
if: ${{github.event_name == 'pull_request'}}
|
if: ${{github.event_name == 'pull_request'}}
|
||||||
- name: install
|
- name: install
|
||||||
if: ${{github.event_name == 'pull_request'}}
|
if: ${{github.event_name == 'pull_request'}}
|
||||||
@@ -704,23 +705,26 @@ jobs:
|
|||||||
pip3 install toml
|
pip3 install toml
|
||||||
gcc --version
|
gcc --version
|
||||||
python3 --version
|
python3 --version
|
||||||
- uses: actions/download-artifact@v2
|
- uses: actions/download-artifact@v4
|
||||||
if: ${{github.event_name == 'pull_request'}}
|
if: ${{github.event_name == 'pull_request'}}
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
with:
|
with:
|
||||||
name: sizes
|
pattern: '{sizes,sizes-*}'
|
||||||
|
merge-multiple: true
|
||||||
path: sizes
|
path: sizes
|
||||||
- uses: actions/download-artifact@v2
|
- uses: actions/download-artifact@v4
|
||||||
if: ${{github.event_name == 'pull_request'}}
|
if: ${{github.event_name == 'pull_request'}}
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
with:
|
with:
|
||||||
name: cov
|
pattern: '{cov,cov-*}'
|
||||||
|
merge-multiple: true
|
||||||
path: cov
|
path: cov
|
||||||
- uses: actions/download-artifact@v2
|
- uses: actions/download-artifact@v4
|
||||||
if: ${{github.event_name == 'pull_request'}}
|
if: ${{github.event_name == 'pull_request'}}
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
with:
|
with:
|
||||||
name: bench
|
pattern: '{bench,bench-*}'
|
||||||
|
merge-multiple: true
|
||||||
path: bench
|
path: bench
|
||||||
|
|
||||||
# try to find results from tests
|
# try to find results from tests
|
||||||
@@ -862,7 +866,7 @@ jobs:
|
|||||||
body: $comment,
|
body: $comment,
|
||||||
}' | tee comment/comment.json
|
}' | tee comment/comment.json
|
||||||
- name: upload-comment
|
- name: upload-comment
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: comment
|
name: comment
|
||||||
path: comment
|
path: comment
|
||||||
|
|||||||
16
lfs.c
16
lfs.c
@@ -3664,22 +3664,16 @@ static lfs_ssize_t lfs_file_write_(lfs_t *lfs, lfs_file_t *file,
|
|||||||
static lfs_soff_t lfs_file_seek_(lfs_t *lfs, lfs_file_t *file,
|
static lfs_soff_t lfs_file_seek_(lfs_t *lfs, lfs_file_t *file,
|
||||||
lfs_soff_t off, int whence) {
|
lfs_soff_t off, int whence) {
|
||||||
// find new pos
|
// find new pos
|
||||||
|
//
|
||||||
|
// fortunately for us, littlefs is limited to 31-bit file sizes, so we
|
||||||
|
// don't have to worry too much about integer overflow
|
||||||
lfs_off_t npos = file->pos;
|
lfs_off_t npos = file->pos;
|
||||||
if (whence == LFS_SEEK_SET) {
|
if (whence == LFS_SEEK_SET) {
|
||||||
npos = off;
|
npos = off;
|
||||||
} else if (whence == LFS_SEEK_CUR) {
|
} else if (whence == LFS_SEEK_CUR) {
|
||||||
if ((lfs_soff_t)file->pos + off < 0) {
|
npos = file->pos + (lfs_off_t)off;
|
||||||
return LFS_ERR_INVAL;
|
|
||||||
} else {
|
|
||||||
npos = file->pos + off;
|
|
||||||
}
|
|
||||||
} else if (whence == LFS_SEEK_END) {
|
} else if (whence == LFS_SEEK_END) {
|
||||||
lfs_soff_t res = lfs_file_size_(lfs, file) + off;
|
npos = (lfs_off_t)lfs_file_size_(lfs, file) + (lfs_off_t)off;
|
||||||
if (res < 0) {
|
|
||||||
return LFS_ERR_INVAL;
|
|
||||||
} else {
|
|
||||||
npos = res;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (npos > lfs->file_max) {
|
if (npos > lfs->file_max) {
|
||||||
|
|||||||
@@ -405,3 +405,111 @@ code = '''
|
|||||||
lfs_file_close(&lfs, &file) => 0;
|
lfs_file_close(&lfs, &file) => 0;
|
||||||
lfs_unmount(&lfs) => 0;
|
lfs_unmount(&lfs) => 0;
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
# test possible overflow/underflow conditions
|
||||||
|
#
|
||||||
|
# note these need -fsanitize=undefined to consistently detect
|
||||||
|
# overflow/underflow conditions
|
||||||
|
|
||||||
|
[cases.test_seek_filemax]
|
||||||
|
code = '''
|
||||||
|
lfs_t lfs;
|
||||||
|
lfs_format(&lfs, cfg) => 0;
|
||||||
|
lfs_mount(&lfs, cfg) => 0;
|
||||||
|
lfs_file_t file;
|
||||||
|
lfs_file_open(&lfs, &file, "kitty",
|
||||||
|
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0;
|
||||||
|
uint8_t buffer[1024];
|
||||||
|
strcpy((char*)buffer, "kittycatcat");
|
||||||
|
size_t size = strlen((char*)buffer);
|
||||||
|
lfs_file_write(&lfs, &file, buffer, size) => size;
|
||||||
|
|
||||||
|
// seek with LFS_SEEK_SET
|
||||||
|
lfs_file_seek(&lfs, &file, LFS_FILE_MAX, LFS_SEEK_SET) => LFS_FILE_MAX;
|
||||||
|
|
||||||
|
// seek with LFS_SEEK_CUR
|
||||||
|
lfs_file_seek(&lfs, &file, 0, LFS_SEEK_CUR) => LFS_FILE_MAX;
|
||||||
|
|
||||||
|
// the file hasn't changed size, so seek end takes us back to the offset=0
|
||||||
|
lfs_file_seek(&lfs, &file, +10, LFS_SEEK_END) => size+10;
|
||||||
|
|
||||||
|
lfs_file_close(&lfs, &file) => 0;
|
||||||
|
lfs_unmount(&lfs) => 0;
|
||||||
|
'''
|
||||||
|
|
||||||
|
[cases.test_seek_underflow]
|
||||||
|
code = '''
|
||||||
|
lfs_t lfs;
|
||||||
|
lfs_format(&lfs, cfg) => 0;
|
||||||
|
lfs_mount(&lfs, cfg) => 0;
|
||||||
|
lfs_file_t file;
|
||||||
|
lfs_file_open(&lfs, &file, "kitty",
|
||||||
|
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0;
|
||||||
|
uint8_t buffer[1024];
|
||||||
|
strcpy((char*)buffer, "kittycatcat");
|
||||||
|
size_t size = strlen((char*)buffer);
|
||||||
|
lfs_file_write(&lfs, &file, buffer, size) => size;
|
||||||
|
|
||||||
|
// underflow with LFS_SEEK_CUR, should error
|
||||||
|
lfs_file_seek(&lfs, &file, -(size+10), LFS_SEEK_CUR) => LFS_ERR_INVAL;
|
||||||
|
lfs_file_seek(&lfs, &file, -LFS_FILE_MAX, LFS_SEEK_CUR) => LFS_ERR_INVAL;
|
||||||
|
lfs_file_seek(&lfs, &file, -(size+LFS_FILE_MAX), LFS_SEEK_CUR)
|
||||||
|
=> LFS_ERR_INVAL;
|
||||||
|
|
||||||
|
// underflow with LFS_SEEK_END, should error
|
||||||
|
lfs_file_seek(&lfs, &file, -(size+10), LFS_SEEK_END) => LFS_ERR_INVAL;
|
||||||
|
lfs_file_seek(&lfs, &file, -LFS_FILE_MAX, LFS_SEEK_END) => LFS_ERR_INVAL;
|
||||||
|
lfs_file_seek(&lfs, &file, -(size+LFS_FILE_MAX), LFS_SEEK_END)
|
||||||
|
=> LFS_ERR_INVAL;
|
||||||
|
|
||||||
|
// file pointer should not have changed
|
||||||
|
lfs_file_tell(&lfs, &file) => size;
|
||||||
|
|
||||||
|
lfs_file_close(&lfs, &file) => 0;
|
||||||
|
lfs_unmount(&lfs) => 0;
|
||||||
|
'''
|
||||||
|
|
||||||
|
[cases.test_seek_overflow]
|
||||||
|
code = '''
|
||||||
|
lfs_t lfs;
|
||||||
|
lfs_format(&lfs, cfg) => 0;
|
||||||
|
lfs_mount(&lfs, cfg) => 0;
|
||||||
|
lfs_file_t file;
|
||||||
|
lfs_file_open(&lfs, &file, "kitty",
|
||||||
|
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0;
|
||||||
|
uint8_t buffer[1024];
|
||||||
|
strcpy((char*)buffer, "kittycatcat");
|
||||||
|
size_t size = strlen((char*)buffer);
|
||||||
|
lfs_file_write(&lfs, &file, buffer, size) => size;
|
||||||
|
|
||||||
|
// seek to LFS_FILE_MAX
|
||||||
|
lfs_file_seek(&lfs, &file, LFS_FILE_MAX, LFS_SEEK_SET) => LFS_FILE_MAX;
|
||||||
|
|
||||||
|
// overflow with LFS_SEEK_CUR, should error
|
||||||
|
lfs_file_seek(&lfs, &file, +10, LFS_SEEK_CUR) => LFS_ERR_INVAL;
|
||||||
|
lfs_file_seek(&lfs, &file, +LFS_FILE_MAX, LFS_SEEK_CUR) => LFS_ERR_INVAL;
|
||||||
|
|
||||||
|
// LFS_SEEK_SET/END don't care about the current file position, but we can
|
||||||
|
// still overflow with a large offset
|
||||||
|
|
||||||
|
// overflow with LFS_SEEK_SET, should error
|
||||||
|
lfs_file_seek(&lfs, &file,
|
||||||
|
+((uint32_t)LFS_FILE_MAX+10),
|
||||||
|
LFS_SEEK_SET) => LFS_ERR_INVAL;
|
||||||
|
lfs_file_seek(&lfs, &file,
|
||||||
|
+((uint32_t)LFS_FILE_MAX+(uint32_t)LFS_FILE_MAX),
|
||||||
|
LFS_SEEK_SET) => LFS_ERR_INVAL;
|
||||||
|
|
||||||
|
// overflow with LFS_SEEK_END, should error
|
||||||
|
lfs_file_seek(&lfs, &file, +(LFS_FILE_MAX-size+10), LFS_SEEK_END)
|
||||||
|
=> LFS_ERR_INVAL;
|
||||||
|
lfs_file_seek(&lfs, &file, +(LFS_FILE_MAX-size+LFS_FILE_MAX), LFS_SEEK_END)
|
||||||
|
=> LFS_ERR_INVAL;
|
||||||
|
|
||||||
|
// file pointer should not have changed
|
||||||
|
lfs_file_tell(&lfs, &file) => LFS_FILE_MAX;
|
||||||
|
|
||||||
|
lfs_file_close(&lfs, &file) => 0;
|
||||||
|
lfs_unmount(&lfs) => 0;
|
||||||
|
'''
|
||||||
|
|||||||
Reference in New Issue
Block a user