[Annotation] Avoid to encrypt the appearance stream two times (bug 1815476)

This commit is contained in:
Calixte Denizet 2023-02-07 19:26:46 +01:00
parent c971f4a0a9
commit ea7b4b4d6c
6 changed files with 34 additions and 19 deletions

View File

@ -1894,13 +1894,11 @@ class WidgetAnnotation extends Annotation {
let newTransform = null;
if (encrypt) {
newTransform = encrypt.createCipherTransform(newRef.num, newRef.gen);
appearance = newTransform.encryptString(appearance);
}
const resources = this._getSaveFieldResources(xref);
const appearanceStream = new StringStream(appearance);
const appearanceDict = (appearanceStream.dict = new Dict(xref));
appearanceDict.set("Length", appearance.length);
appearanceDict.set("Subtype", Name.get("Form"));
appearanceDict.set("Resources", resources);
appearanceDict.set("BBox", [
@ -3669,7 +3667,6 @@ class FreeTextAnnotation extends MarkupAnnotation {
appearanceStreamDict.set("Subtype", Name.get("Form"));
appearanceStreamDict.set("Type", Name.get("XObject"));
appearanceStreamDict.set("BBox", [0, 0, w, h]);
appearanceStreamDict.set("Length", appearance.length);
appearanceStreamDict.set("Resources", resources);
if (rotation) {

View File

@ -45,13 +45,13 @@ function writeDict(dict, buffer, transform) {
}
function writeStream(stream, buffer, transform) {
writeDict(stream.dict, buffer, transform);
buffer.push(" stream\n");
let string = stream.getString();
if (transform !== null) {
string = transform.encryptString(string);
}
buffer.push(string, "\nendstream");
stream.dict.set("Length", string.length);
writeDict(stream.dict, buffer, transform);
buffer.push(" stream\n", string, "\nendstream");
}
function writeArray(array, buffer, transform) {

View File

@ -571,3 +571,4 @@
!autoprint.pdf
!bug1811694.pdf
!bug1811510.pdf
!bug1815476.pdf

BIN
test/pdfs/bug1815476.pdf Executable file

Binary file not shown.

View File

@ -7332,5 +7332,22 @@
"rounds": 1,
"link": true,
"type": "eq"
},
{
"id": "bug1815476-save-print",
"file": "pdfs/bug1815476.pdf",
"md5": "476f77da5f9422ef86ea5f4531602e93",
"rounds": 1,
"type": "eq",
"save": true,
"print": true,
"annotationStorage": {
"88R": {
"value": "foo"
},
"87R": {
"value": "bar"
}
}
}
]

View File

@ -2062,8 +2062,8 @@ describe("annotation", function () {
"/V (hello world) /AP << /N 2 0 R>> /M (date)>>\nendobj\n"
);
expect(newData.data).toEqual(
"2 0 obj\n<< /Length 74 /Subtype /Form /Resources " +
"<< /Font << /Helv 314 0 R>>>> /BBox [0 0 32 10]>> stream\n" +
"2 0 obj\n<< /Subtype /Form /Resources " +
"<< /Font << /Helv 314 0 R>>>> /BBox [0 0 32 10] /Length 74>> stream\n" +
"/Tx BMC q BT /Helv 5 Tf 1 0 0 1 0 0 Tm 2 3.07 Td (hello world) Tj " +
"ET Q EMC\nendstream\nendobj\n"
);
@ -2108,8 +2108,8 @@ describe("annotation", function () {
"/V (hello world) /MK << /R 90>> /AP << /N 2 0 R>> /M (date)>>\nendobj\n"
);
expect(newData.data).toEqual(
"2 0 obj\n<< /Length 74 /Subtype /Form /Resources " +
"<< /Font << /Helv 314 0 R>>>> /BBox [0 0 32 10] /Matrix [0 1 -1 0 32 0]>> stream\n" +
"2 0 obj\n<< /Subtype /Form /Resources " +
"<< /Font << /Helv 314 0 R>>>> /BBox [0 0 32 10] /Matrix [0 1 -1 0 32 0] /Length 74>> stream\n" +
"/Tx BMC q BT /Helv 5 Tf 1 0 0 1 0 0 Tm 2 2.94 Td (hello world) Tj " +
"ET Q EMC\nendstream\nendobj\n"
);
@ -2239,8 +2239,8 @@ describe("annotation", function () {
`/V (\xfe\xff${utf16String}) /AP << /N 2 0 R>> /M (date)>>\nendobj\n`
);
expect(newData.data).toEqual(
"2 0 obj\n<< /Length 79 /Subtype /Form /Resources " +
"<< /Font << /Helv 314 0 R /Goth 159 0 R>>>> /BBox [0 0 32 10]>> stream\n" +
"2 0 obj\n<< /Subtype /Form /Resources " +
"<< /Font << /Helv 314 0 R /Goth 159 0 R>>>> /BBox [0 0 32 10] /Length 79>> stream\n" +
`/Tx BMC q BT /Goth 5 Tf 1 0 0 1 0 0 Tm 2 3.07 Td (${utf16String}) Tj ` +
"ET Q EMC\nendstream\nendobj\n"
);
@ -3626,8 +3626,8 @@ describe("annotation", function () {
expect(newData.data).toEqual(
[
"2 0 obj",
"<< /Length 170 /Subtype /Form /Resources << /Font << /Helv 314 0 R>>>> " +
"/BBox [0 0 32 10] /Matrix [0 -1 1 0 0 10]>> stream",
"<< /Subtype /Form /Resources << /Font << /Helv 314 0 R>>>> " +
"/BBox [0 0 32 10] /Matrix [0 -1 1 0 0 10] /Length 170>> stream",
"/Tx BMC q",
"1 1 10 32 re W n",
"0.600006 0.756866 0.854904 rg",
@ -3687,8 +3687,8 @@ describe("annotation", function () {
expect(newData.data).toEqual(
[
"2 0 obj",
"<< /Length 133 /Subtype /Form /Resources << /Font << /Helv 314 0 R>>>> " +
"/BBox [0 0 32 10]>> stream",
"<< /Subtype /Form /Resources << /Font << /Helv 314 0 R>>>> " +
"/BBox [0 0 32 10] /Length 133>> stream",
"/Tx BMC q",
"1 1 32 10 re W n",
"0.600006 0.756866 0.854904 rg",
@ -3753,8 +3753,8 @@ describe("annotation", function () {
expect(newData.data).toEqual(
[
"2 0 obj",
"<< /Length 171 /Subtype /Form /Resources << /Font << /Helv 314 0 R>>>> " +
"/BBox [0 0 32 10]>> stream",
"<< /Subtype /Form /Resources << /Font << /Helv 314 0 R>>>> " +
"/BBox [0 0 32 10] /Length 171>> stream",
"/Tx BMC q",
"1 1 32 10 re W n",
"0.600006 0.756866 0.854904 rg",
@ -4058,7 +4058,7 @@ describe("annotation", function () {
expect(appearance).toEqual(
"3 0 obj\n" +
"<< /FormType 1 /Subtype /Form /Type /XObject /BBox [0 0 44 44] " +
"/Length 101 /Resources << /Font << /Helv 1 0 R>>>>>> stream\n" +
"/Resources << /Font << /Helv 1 0 R>>>> /Length 101>> stream\n" +
"q\n" +
"0 0 44 44 re W n\n" +
"BT\n" +