Просмотр исходного кода

Merge pull request #10246 from overleaf/jpa-pdf-caching-object-id-back-fill

[web] pdf-caching: double down on back-filling of object-id

GitOrigin-RevId: 751392dc5ed59eb621eca3813040c7b92ef1369e
Jakob Ackermann 4 лет назад
Родитель
Сommit
6f00659865
1 измененных файлов с 12 добавлено и 3 удалено
  1. 12 3
      services/web/frontend/js/features/pdf-preview/util/pdf-caching.js

+ 12 - 3
services/web/frontend/js/features/pdf-preview/util/pdf-caching.js

@@ -125,10 +125,19 @@ function backFillObjectContext(chunk, arrayBuffer) {
     return new Uint8Array(arrayBuffer)
     return new Uint8Array(arrayBuffer)
   }
   }
   const { size, objectId } = chunk
   const { size, objectId } = chunk
-  const header = Uint8Array.from(objectId)
   const fullBuffer = new Uint8Array(size)
   const fullBuffer = new Uint8Array(size)
-  fullBuffer.set(header, 0)
-  fullBuffer.set(new Uint8Array(arrayBuffer), objectId.length)
+  const sourceBuffer = new Uint8Array(arrayBuffer)
+  try {
+    fullBuffer.set(objectId, 0)
+    fullBuffer.set(sourceBuffer, objectId.byteLength)
+  } catch (err) {
+    throw OError.tag(err, 'broken back-filling of object-id', {
+      objectIdByteLength: objectId.byteLength,
+      fullBufferByteLength: fullBuffer.byteLength,
+      arrayBufferByteLength: arrayBuffer.byteLength,
+      sourceBufferByteLength: sourceBuffer.byteLength,
+    })
+  }
   return fullBuffer
   return fullBuffer
 }
 }