mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 10:30:15 +02:00
Prevent possible race condition when reading metadata #3451
This commit is contained in:
parent
3a64a0529a
commit
df971207b8
@ -4,6 +4,11 @@
|
|||||||
|
|
||||||
Requires libvips v8.13.3
|
Requires libvips v8.13.3
|
||||||
|
|
||||||
|
### v0.31.3 - TBD
|
||||||
|
|
||||||
|
* Prevent possible race condition awaiting metadata of Stream-based input.
|
||||||
|
[#3451](https://github.com/lovell/sharp/issues/3451)
|
||||||
|
|
||||||
### v0.31.2 - 4th November 2022
|
### v0.31.2 - 4th November 2022
|
||||||
|
|
||||||
* Upgrade to libvips v8.13.3 for upstream bug fixes.
|
* Upgrade to libvips v8.13.3 for upstream bug fixes.
|
||||||
|
@ -469,7 +469,7 @@ function metadata (callback) {
|
|||||||
} else {
|
} else {
|
||||||
if (this._isStreamInput()) {
|
if (this._isStreamInput()) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.on('finish', () => {
|
const finished = () => {
|
||||||
this._flattenBufferIn();
|
this._flattenBufferIn();
|
||||||
sharp.metadata(this.options, (err, metadata) => {
|
sharp.metadata(this.options, (err, metadata) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -478,7 +478,12 @@ function metadata (callback) {
|
|||||||
resolve(metadata);
|
resolve(metadata);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
};
|
||||||
|
if (this.writableFinished) {
|
||||||
|
finished();
|
||||||
|
} else {
|
||||||
|
this.once('finish', finished);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
@ -439,6 +439,19 @@ describe('Image metadata', function () {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Stream in, finish event fires before metadata is requested', (done) => {
|
||||||
|
const create = { width: 1, height: 1, channels: 3, background: 'red' };
|
||||||
|
const image1 = sharp({ create }).png().pipe(sharp());
|
||||||
|
const image2 = sharp({ create }).png().pipe(sharp());
|
||||||
|
process.nextTick(async () => {
|
||||||
|
const data1 = await image1.metadata();
|
||||||
|
assert.strictEqual('png', data1.format);
|
||||||
|
const data2 = await image2.metadata();
|
||||||
|
assert.strictEqual('png', data2.format);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Stream', function (done) {
|
it('Stream', function (done) {
|
||||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
const pipeline = sharp().metadata(function (err, metadata) {
|
const pipeline = sharp().metadata(function (err, metadata) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user