@harperfast/rocksdb-js 1.4.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1834,7 +1834,7 @@ var RocksDatabase = class RocksDatabase extends DBI {
1834
1834
 
1835
1835
  //#endregion
1836
1836
  //#region src/parse-transaction-log.ts
1837
- const { TRANSACTION_LOG_TOKEN } = constants;
1837
+ const { TRANSACTION_LOG_TOKEN, TRANSACTION_LOG_ENTRY_HEADER_SIZE: TRANSACTION_LOG_ENTRY_HEADER_SIZE$1 } = constants;
1838
1838
  const MIN_VALID_TIMESTAMP = Date.UTC(2026, 0, 27);
1839
1839
  const VALID_FLAGS_MASK = 1;
1840
1840
  /**
@@ -1858,7 +1858,11 @@ function parseTransactionLog(path, options = {}) {
1858
1858
  const buffer = Buffer.allocUnsafe(numBytes);
1859
1859
  const bytesRead = readSync(fileHandle, buffer, 0, numBytes, fileOffset);
1860
1860
  fileOffset += bytesRead;
1861
- if (bytesRead !== numBytes) throw new Error(`Expected to read ${numBytes} bytes but only read ${bytesRead}, file offset: ${fileOffset}, file size: ${size}, file path: ${path}, buffer: ${buffer.toString("hex")}`);
1861
+ if (bytesRead !== numBytes) {
1862
+ const previewBytes = Math.min(bytesRead, 64);
1863
+ const preview = buffer.subarray(0, previewBytes).toString("hex");
1864
+ throw new Error(`Expected to read ${numBytes} bytes but only read ${bytesRead}, file offset: ${fileOffset.toString(16)}, file size: ${size}, file path: ${path}, buffer (first ${previewBytes} bytes): ${preview}`);
1865
+ }
1862
1866
  return buffer;
1863
1867
  };
1864
1868
  try {
@@ -1878,6 +1882,11 @@ function parseTransactionLog(path, options = {}) {
1878
1882
  }
1879
1883
  const length = read(4).readUInt32BE(0);
1880
1884
  const flags = read(1).readUInt8(0);
1885
+ const remaining = size - fileOffset;
1886
+ if (length > remaining) {
1887
+ const entryOffset = fileOffset - TRANSACTION_LOG_ENTRY_HEADER_SIZE$1;
1888
+ throw new Error(`Corrupt entry at offset ${entryOffset.toString(16)}: declared length ${length} exceeds ${remaining} bytes remaining (file size: ${size})`);
1889
+ }
1881
1890
  const data = read(length);
1882
1891
  const entryAnomalies = [];
1883
1892
  if (!Number.isFinite(timestamp) || timestamp < MIN_VALID_TIMESTAMP) entryAnomalies.push(`timestamp ${timestamp} predates 2026-01-27 (possible corruption)`);
@@ -1997,14 +2006,17 @@ Object.defineProperty(TransactionLog.prototype, "query", { value({ start, end, e
1997
2006
  try {
1998
2007
  timestamp = dataView.getFloat64(position);
1999
2008
  } catch (error) {
2000
- error.message += ` at position ${position} of log ${logBuffer.logId} (size=${size}, log buffer length=${logBuffer.length})`;
2009
+ error.message += ` at position ${position.toString(16)} of log ${logBuffer.logId} (size=${size}, log buffer length=${logBuffer.length})`;
2001
2010
  throw error;
2002
2011
  }
2003
2012
  if (!timestamp) return {
2004
2013
  done: true,
2005
2014
  value: void 0
2006
2015
  };
2016
+ const limit = readUncommitted ? logBuffer.length : size;
2017
+ if (position + TRANSACTION_LOG_ENTRY_HEADER_SIZE > limit) throw new RangeError(`Corrupt transaction log: truncated entry header at position ${position.toString(16)} of log ${logBuffer.logId} (available=${limit - position})`);
2007
2018
  const length = dataView.getUint32(position + 8);
2019
+ if (position + TRANSACTION_LOG_ENTRY_HEADER_SIZE + length > limit) throw new RangeError(`Corrupt transaction log entry at position ${position.toString(16)} of log ${logBuffer.logId}: declared length ${length} overruns the log (limit=${limit})`);
2008
2020
  position += TRANSACTION_LOG_ENTRY_HEADER_SIZE;
2009
2021
  let matchesRange;
2010
2022
  if (foundExactStart) matchesRange = (!exclusiveStart || timestamp !== start) && timestamp < end;
@@ -2027,7 +2039,12 @@ Object.defineProperty(TransactionLog.prototype, "query", { value({ start, end, e
2027
2039
  const { logId: latestLogId, size: latestSize } = loadLastPosition(transactionLog, !!readUncommitted);
2028
2040
  size = latestSize;
2029
2041
  if (latestLogId > logBuffer.logId) {
2030
- logBuffer = getLogMemoryMap(transactionLog, logBuffer.logId + 1);
2042
+ const nextLogBuffer = getLogMemoryMap(transactionLog, logBuffer.logId + 1);
2043
+ if (!nextLogBuffer) return {
2044
+ done: true,
2045
+ value: void 0
2046
+ };
2047
+ logBuffer = nextLogBuffer;
2031
2048
  dataView = logBuffer.dataView;
2032
2049
  size = logBuffer.size;
2033
2050
  if (size == void 0) {
@@ -2090,7 +2107,7 @@ function loadLastPosition(transactionLog, readUncommitted) {
2090
2107
  //#region src/index.ts
2091
2108
  const versions = {
2092
2109
  rocksdb: version,
2093
- "rocksdb-js": "1.4.1"
2110
+ "rocksdb-js": "1.4.2"
2094
2111
  };
2095
2112
 
2096
2113
  //#endregion