New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@jsreport/pdfjs

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jsreport/pdfjs - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0

test/cross-reference-streams-predictor.pdf

22

lib/mixins/merge.js

@@ -91,3 +91,23 @@ const zlib = require('zlib')

const pageStream = docPage.properties.get('Contents').object.content
let pageStream
if (Array.isArray(docPage.properties.get('Contents'))) {
// if there are multiple page streams, we concat them into one
let content = ''
for (const c of docPage.properties.get('Contents')) {
if (c.object.content.object.properties.get('Filter')) {
content += zlib.unzipSync(c.object.content.content).toString('latin1') + '\n'
} else {
content += uint8ToString(c.object.content.content) + '\n'
}
}
pageStream = docPage.properties.get('Contents')[0].object.content
pageStream.content = zlib.deflateSync(Buffer.from(content, 'latin1'))
pageStream.object.prop('Length', content.length)
pageStream.object.prop('Filter', 'FlateDecode')
docPage.properties.set('Contents', docPage.properties.get('Contents')[0])
} else {
pageStream = docPage.properties.get('Contents').object.content
}
if (pageStream.object.properties.get('Filter')) {

@@ -94,0 +114,0 @@ pageStream.content = zlib.unzipSync(pageStream.content).toString('latin1')

2

lib/object/string.js

@@ -177,3 +177,3 @@ // pofider changes

case 0x0a: // LF
lexer.skipEOL(1)
lexer.skipEOL(1, true)
break

@@ -180,0 +180,0 @@ default:

const zlib = require('zlib')
module.exports.inflate = (obj) => {
return zlib.unzipSync(obj.content.content)
exports.inflate = function (obj) {
let filters = obj.properties.get('Filter')
let filter
if (filters && Array.isArray(filters)) {
filter = filters.shift()
} else {
filter = filters
filters = []
}
if (!filter || filter.name !== 'FlateDecode' || filters.length > 0) {
throw new Error('Only FlateDecode filter are supported')
}
let columns = 1
let predictor = 1
const params = obj.properties.get('DecodeParms')
if (params) {
columns = params.get('Columns')
predictor = params.get('Predictor')
}
let res = zlib.unzipSync(obj.content.content)
if (predictor === 1) {
return res
}
if (predictor >= 10 && predictor <= 15) {
// PNG filter
res = pngFilter(res, columns)
} else {
throw new Error('Unsupported predictor ' + predictor)
}
return res
}
function pngFilter (src, columns) {
const columnCount = columns + 1
const rowCount = src.length / columnCount
const res = new Uint8Array(columns * rowCount)
for (let y = 0; y < rowCount; ++y) {
const filter = src[y * columnCount]
if (filter === 0) {
for (let x = 0; x < columns; ++x) {
res[y * columns + x] = src[y * columnCount + 1 + x]
}
} else if (filter === 2) {
for (let x = 0; x < columns; x++) {
const prev = (y === 0) ? 0 : res[(y - 1) * columns + x]
res[y * columns + x] = (prev + src[y * columnCount + 1 + x]) & 0xff
}
} else {
throw new Error('Unsupported PNG filter ' + filter)
}
}
return res
}
exports.toArrayBuffer = function (b) {

@@ -8,0 +65,0 @@ if (b instanceof ArrayBuffer) {

{
"name": "@jsreport/pdfjs",
"version": "1.3.0",
"version": "1.4.0",
"description": "",

@@ -13,7 +13,7 @@ "main": "index.js",

},
"dependencies": {
"dependencies": {
"@jsreport/node-signpdf": "1.4.2",
"crypto-js": "4.1.1",
"parse-color": "1.0.0",
"pdfjs-dist": "2.14.305"
"pdfjs-dist": "2.16.105"
},

@@ -20,0 +20,0 @@ "devDependencies": {

@@ -873,2 +873,12 @@ const { Document, External } = require('../')

it('handle cross reference streams with predictor', async () => {
const document = new Document()
const external = new External(fs.readFileSync(path.join(__dirname, 'cross-reference-streams-predictor.pdf')))
document.append(external)
const buffer = await document.asBuffer()
fs.writeFileSync('out.pdf', buffer)
const { catalog } = await validate(buffer)
catalog.properties.get('Pages').object.properties.get('Kids').should.have.length(1)
})
it('pdf/A basic', async () => {

@@ -875,0 +885,0 @@ const document = new Document()

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc