@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.cjs CHANGED
@@ -1859,7 +1859,7 @@ var RocksDatabase = class RocksDatabase extends DBI {
1859
1859
 
1860
1860
  //#endregion
1861
1861
  //#region src/parse-transaction-log.ts
1862
- const { TRANSACTION_LOG_TOKEN } = constants;
1862
+ const { TRANSACTION_LOG_TOKEN, TRANSACTION_LOG_ENTRY_HEADER_SIZE: TRANSACTION_LOG_ENTRY_HEADER_SIZE$1 } = constants;
1863
1863
  const MIN_VALID_TIMESTAMP = Date.UTC(2026, 0, 27);
1864
1864
  const VALID_FLAGS_MASK = 1;
1865
1865
  /**
@@ -1883,7 +1883,11 @@ function parseTransactionLog(path, options = {}) {
1883
1883
  const buffer = Buffer.allocUnsafe(numBytes);
1884
1884
  const bytesRead = (0, node_fs.readSync)(fileHandle, buffer, 0, numBytes, fileOffset);
1885
1885
  fileOffset += bytesRead;
1886
- 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")}`);
1886
+ if (bytesRead !== numBytes) {
1887
+ const previewBytes = Math.min(bytesRead, 64);
1888
+ const preview = buffer.subarray(0, previewBytes).toString("hex");
1889
+ 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}`);
1890
+ }
1887
1891
  return buffer;
1888
1892
  };
1889
1893
  try {
@@ -1903,6 +1907,11 @@ function parseTransactionLog(path, options = {}) {
1903
1907
  }
1904
1908
  const length = read(4).readUInt32BE(0);
1905
1909
  const flags = read(1).readUInt8(0);
1910
+ const remaining = size - fileOffset;
1911
+ if (length > remaining) {
1912
+ const entryOffset = fileOffset - TRANSACTION_LOG_ENTRY_HEADER_SIZE$1;
1913
+ throw new Error(`Corrupt entry at offset ${entryOffset.toString(16)}: declared length ${length} exceeds ${remaining} bytes remaining (file size: ${size})`);
1914
+ }
1906
1915
  const data = read(length);
1907
1916
  const entryAnomalies = [];
1908
1917
  if (!Number.isFinite(timestamp) || timestamp < MIN_VALID_TIMESTAMP) entryAnomalies.push(`timestamp ${timestamp} predates 2026-01-27 (possible corruption)`);
@@ -2022,14 +2031,17 @@ Object.defineProperty(TransactionLog.prototype, "query", { value({ start, end, e
2022
2031
  try {
2023
2032
  timestamp = dataView.getFloat64(position);
2024
2033
  } catch (error) {
2025
- error.message += ` at position ${position} of log ${logBuffer.logId} (size=${size}, log buffer length=${logBuffer.length})`;
2034
+ error.message += ` at position ${position.toString(16)} of log ${logBuffer.logId} (size=${size}, log buffer length=${logBuffer.length})`;
2026
2035
  throw error;
2027
2036
  }
2028
2037
  if (!timestamp) return {
2029
2038
  done: true,
2030
2039
  value: void 0
2031
2040
  };
2041
+ const limit = readUncommitted ? logBuffer.length : size;
2042
+ 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})`);
2032
2043
  const length = dataView.getUint32(position + 8);
2044
+ 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})`);
2033
2045
  position += TRANSACTION_LOG_ENTRY_HEADER_SIZE;
2034
2046
  let matchesRange;
2035
2047
  if (foundExactStart) matchesRange = (!exclusiveStart || timestamp !== start) && timestamp < end;
@@ -2052,7 +2064,12 @@ Object.defineProperty(TransactionLog.prototype, "query", { value({ start, end, e
2052
2064
  const { logId: latestLogId, size: latestSize } = loadLastPosition(transactionLog, !!readUncommitted);
2053
2065
  size = latestSize;
2054
2066
  if (latestLogId > logBuffer.logId) {
2055
- logBuffer = getLogMemoryMap(transactionLog, logBuffer.logId + 1);
2067
+ const nextLogBuffer = getLogMemoryMap(transactionLog, logBuffer.logId + 1);
2068
+ if (!nextLogBuffer) return {
2069
+ done: true,
2070
+ value: void 0
2071
+ };
2072
+ logBuffer = nextLogBuffer;
2056
2073
  dataView = logBuffer.dataView;
2057
2074
  size = logBuffer.size;
2058
2075
  if (size == void 0) {
@@ -2115,7 +2132,7 @@ function loadLastPosition(transactionLog, readUncommitted) {
2115
2132
  //#region src/index.ts
2116
2133
  const versions = {
2117
2134
  rocksdb: version,
2118
- "rocksdb-js": "1.4.1"
2135
+ "rocksdb-js": "1.4.2"
2119
2136
  };
2120
2137
 
2121
2138
  //#endregion