Skip to content

Commit

Permalink
fix(svg): adds fix for SVG/EPS crashes #96
Browse files Browse the repository at this point in the history
This changes the output of EPS and SVG data to write to a string buffer
instead of a file buffer. This fixes the issue where the binary would
crash after a substantial number of iterations.
  • Loading branch information
jshor committed Nov 27, 2022
1 parent b5f3b91 commit 300a007
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 33 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/pr.yml
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
os: [windows-2019, ubuntu-latest, macos-latest]
# list only the earliest and latest node versions supported
# this makes PR builds more efficient
node-version: [14, 16]
Expand All @@ -23,7 +23,12 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: yarn

- name: Run linter
run: yarn lint

- name: Build binaries
run: yarn build

- name: Run tests
run: yarn test
45 changes: 18 additions & 27 deletions scripts/patches.js
Expand Up @@ -8,8 +8,8 @@ module.exports = [
files: '.zint/**/zint.h',
from: /struct zint_symbol \{/g,
to: `
struct zint_symbol {
char rendered_data[1000000];
struct zint_symbol {
char rendered_data[1000000];
`
},
/* add stdlib as reference */
Expand All @@ -30,42 +30,33 @@ module.exports = [
{
files: '.zint/**/{svg,ps}.{c,h}',
from: /([a-z]+)\s*=\s*stdout;/g,
to: `
#ifndef _MSC_VER
pipe(p);
$1 = fdopen(p[1], "w");
#else
$1 = fopen("NUL", "w");
setvbuf($1, buf, _IOLBF, sizeof(symbol->rendered_data));
#endif
`
to: ''
},
/* assigns pointer to maintain file buffer */
{
files: '.zint/**/{svg,ps}.{c,h}',
from: /INTERNAL int ([a-z]+)_plot([^\n]+)/g,
to: `
int pipe(int fd[2]);
int close(int fildes);
int read(int fildes, void *buf, unsigned nbytes);
INTERNAL int $1_plot$2
char *buf = malloc(sizeof(symbol->rendered_data));
int p[2];`
char str[sizeof(symbol->rendered_data)];
`
},
/* replaces the file buffer allocation with a string one */
{
files: '.zint/**/{svg,ps}.{c,h}',
from: /FILE \*([a-z]+)/g,
to: 'char *$1 = str'
},
/* change file printing to string concatenation */
{
files: '.zint/**/{svg,ps}.{c,h}',
from: /fprintf\(([a-z]+), /g,
to: '$1 += sprintf($1, '
},
/* reads file buffer into symbol->rendered_data */
{
files: '.zint/**/{svg,ps}.{c,h}',
from: /fflush\(([a-z]+)\);/g,
to: `
fprintf($1, "<<< EOF >>>");
#ifndef _MSC_VER
fflush($1);
close(p[1]);
read(p[0], symbol->rendered_data, sizeof(symbol->rendered_data));
#else
strcpy(symbol->rendered_data, buf);
#endif
`
to: 'strcpy(symbol->rendered_data, str);'
}
]
5 changes: 0 additions & 5 deletions src/lib/binary.ts
Expand Up @@ -71,11 +71,6 @@ function invoke (config: SymbologyConfig, barcodeData: string, outputType: Outpu
const res = binary.createBuffer(symbol, barcodeData)

if (res.code <= 2) {
// remove all data after the trailing EOF marker
res.encodedData = res
.encodedData
.split('<<< EOF >>>')[0]

if (res.code === 0) {
res.message = 'Symbology successfully created.'
}
Expand Down

0 comments on commit 300a007

Please sign in to comment.