Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing check in remove and audit checks in seek #29

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@picovoice/web-utils",
"version": "1.3.1",
"version": "1.3.2",
"description": "Picovoice web utility functions",
"author": "Picovoice",
"license": "Apache-2.0",
Expand Down
11 changes: 10 additions & 1 deletion src/pv_file_idb.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-2023 Picovoice Inc.

You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
file accompanying this source.
Expand Down Expand Up @@ -271,6 +271,10 @@ export class PvFileIDB extends PvFile {
if (!this.exists() && this._mode === "readonly") {
throw new Error(`'${this._path}' doesn't exist.`);
}
if (!this.exists()) {
// This is valid in ISO C but not supported by this current implementation
throw new Error(`'${this._path}' doesn't exist.`);
}

if (offset < 0) {
const err = new Error(`EOF`);
Expand Down Expand Up @@ -309,6 +313,11 @@ export class PvFileIDB extends PvFile {
*/
public async remove(): Promise<void> {
return new Promise(async (resolve, reject) => {
if (!this.exists()) {
reject(new Error("ENOENT"));
return;
}

const numPages = this._meta!.numPages;
const keyRange = IDBKeyRange.bound(this._path, `${this._path}-${PvFileIDB.createPage(numPages)}`);
const store = this._store;
Expand Down
9 changes: 9 additions & 0 deletions src/pv_file_mem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ export class PvFileMem extends PvFile {
if (!this.exists() && this._mode === "readonly") {
throw new Error(`'${this._path}' doesn't exist.`);
}
if (!this.exists()) {
// This is valid in ISO C but not supported by this current implementation
throw new Error(`'${this._path}' doesn't exist.`);
}

if (offset < 0) {
const err = new Error(`EOF`);
err.name = "EndOfFile";
Expand Down Expand Up @@ -111,6 +116,10 @@ export class PvFileMem extends PvFile {
}

public async remove(): Promise<void> {
if (!this.exists()) {
throw new Error("ENOENT");
}

PvFileMem._memFiles.delete(this._path);
this._pos = 0;
}
Expand Down
Loading