summaryrefslogtreecommitdiff
path: root/src/node_zlib.cc
AgeCommit message (Collapse)Author
2017-08-23src: fixup strings, reduce duplicationJames M Snell
PR-URL: https://github.com/nodejs/node/pull/14937 Reviewed-By: Anna Henningsen <anna@addaleax.net>
2017-08-10zlib: check cleanup return valuesAnna Henningsen
PR-URL: https://github.com/nodejs/node/pull/14673 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-08-09zlib: fix crash when initializing failedAnna Henningsen
Unset `mode_` when initializing the zlib stream failed, so that we don’t try to call the zlib end functions (`deflateEnd()` etc.) when cleaning up in `ZCtx::Close()`. Fixes: https://github.com/nodejs/node/issues/14178 Ref: https://github.com/nodejs/node/pull/13098 PR-URL: https://github.com/nodejs/node/pull/14666 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
2017-06-13zlib: improve performanceBrian White
PR-URL: https://github.com/nodejs/node/pull/13322 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2017-05-22zlib: fix node crashing on invalid optionsAlexey Orlenko
This commit fixes the Node process crashing when constructors of classes of the zlib module are given invalid options. * Throw an Error when the zlib library rejects the value of windowBits, instead of crashing with an assertion. * Treat windowBits and memLevel options consistently with other ones and don't crash when non-numeric values are given. * Fix bugs in the validation logic: - Don't conflate 0 and undefined when checking if a field of an options object exists. - Treat NaN and Infinity values the same way as values of invalid types instead of allowing to actually set zlib options to NaN or Infinity. PR-URL: https://github.com/nodejs/node/pull/13098 Fixes: https://github.com/nodejs/node/issues/13082 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2017-05-10async_wrap,src: add GetAsyncId() methodTrevor Norris
Allow handles to retrieve their own uid's by adding a new method on the FunctionTemplates. Implementation of these into all other classes will come in a future commit. Add the method AsyncWrap::GetAsyncId() to all inheriting class objects so the uid of the handle can be retrieved from JS. In all applicable locations, run ClearWrap() on the object holding the pointer so that it never points to invalid memory and make sure Wrap() is always run so the class pointer is correctly attached to the object and can be retrieved so GetAsyncId() can be run. In many places a class instance was not removing its own pointer from object() in the destructor. This left an invalid pointer in the JS object that could cause the application to segfault under certain conditions. Remove ClearWrap() from ReqWrap for continuity. The ReqWrap constructor was not the one to call Wrap(), so it shouldn't be the one to call ClearWrap(). Wrap() has been added to all constructors that inherit from AsyncWrap. Normally it's the child most class. Except in the case of HandleWrap. Which must be the constructor that runs Wrap() because the class pointer is retrieved for certain calls and because other child classes have multiple inheritance to pointer to the HandleWrap needs to be stored. ClearWrap() has been placed in all FunctionTemplate constructors so that no random values are returned when running getAsyncId(). ClearWrap() has also been placed in all class destructors, except in those that use MakeWeak() because the destructor will run during GC. Making the object() inaccessible. It could be simplified to where AsyncWrap sets the internal pointer, then if an inheriting class needs one of it's own it could set it again. But the inverse would need to be true also, where AsyncWrap then also runs ClearWeak. Unforunately because some of the handles are cleaned up during GC that's impossible. Also in the case of ReqWrap it runs Reset() in the destructor, making the object() inaccessible. Meaning, ClearWrap() must be run by the class that runs Wrap(). There's currently no generalized way of taking care of this across all instances of AsyncWrap. I'd prefer that there be checks in there for these things, but haven't found a way to place them that wouldn't be just as unreliable. Add test that checks all resources that can run getAsyncId(). Would like a way to enforce that any new classes that can also run getAsyncId() are tested, but don't have one. PR-URL: https://github.com/nodejs/node/pull/12892 Ref: https://github.com/nodejs/node/pull/11883 Ref: https://github.com/nodejs/node/pull/8531 Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2017-04-16zlib: remove unused declarationAnna Henningsen
Overlooked in https://github.com/nodejs/node/pull/12366. Removing this removes a compiler warning. PR-URL: https://github.com/nodejs/node/pull/12432 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
2017-04-14src: reduce number of exported symbolsAnna Henningsen
Use `static` definitions and anonymous namespaces to reduce the number of symbols that are exported from the `node` binary. PR-URL: https://github.com/nodejs/node/pull/12366 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-03-10meta: restore original copyright headerJames M Snell
A prior io.js era commit inappropriately removed the original copyright statements from the source. This restores those in any files still remaining from that edit. Ref: https://github.com/nodejs/TSC/issues/174 Ref: https://github.com/nodejs/node/pull/10599 PR-URL: https://github.com/nodejs/node/pull/10155 Note: This PR was required, reviewed-by and approved by the Node.js Foundation Legal Committee and the TSC. There is no `Approved-By:` meta data.
2016-09-20zlib: fix raw inflate with custom dictionaryTarjei Husøy
Moves inflateSetDictionary right after inflateInit2 when mode is INFLATERAW, since without the wrapper in appears zlib won't return Z_NEED_DICT as it would otherwise, and will thus attempt inflating without the dictionary, leading to an error. Fixes: https://github.com/nodejs/node/issues/8507 PR-URL: https://github.com/nodejs/node/pull/8512 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-08-08src: remove unused using declsHaojian Wu
PR-URL: https://github.com/nodejs/node/pull/7990 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Minwoo Jung <jmwsoft@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com>
2016-08-08zlib: remove unneeded propertyJan Schär
PR-URL: https://github.com/nodejs/node/pull/7987 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
2016-06-29src: fix use-after-return in zlib bindingsBen Noordhuis
Pointed out by Coverity. Introduced in commit 5b8e1dab from September 2011 ("Initial pass at zlib bindings".) The asynchronous version of Write() used a pointer to a stack-allocated buffer on flush. A mitigating factor is that zlib does not dereference the pointer for zero-sized writes but it's still technically UB. PR-URL: https://github.com/nodejs/node/pull/7374 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2016-06-28src: fix whitespace/blank_line cpplint warningsBen Noordhuis
PR-URL: https://github.com/nodejs/node/pull/7462 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2016-06-11zlib: move constants into zlib.constantsJames M Snell
zlib constants were previously being added to binding in node_zlib.cc. This moves the zlib constants to node_constants.cc for consistency with the recent constants refactoring: https://github.com/nodejs/node/pull/6534 Adds require('zlib').constants to expose the constants Docs-only deprecates the constants hung directly off require('zlib') Removes a couple constants from the docs that apparently no longer exist in the code PR-URL: https://github.com/nodejs/node/pull/7203 Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-05-24src: no abort from getter if object isn't wrappedTrevor Norris
v8::Object::GetAlignedPointerFromInternalField() returns a random value if Wrap() hasn't been run on the object handle. Causing v8 to abort if certain getters are accessed. It's possible to access these getters and functions during class construction through the AsyncWrap init() callback, and also possible in a subset of those scenarios while running the persistent handle visitor. Mitigate this issue by manually setting the internal aligned pointer field to nullptr in the BaseObject constructor and add necessary logic to return appropriate values when nullptr is encountered. PR-URL: https://github.com/nodejs/node/pull/6184 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net>
2016-04-05zlib: detect gzip files when using unzip*Anna Henningsen
Detect whether a gzip file is being passed to `unzip*` by testing the first bytes for the gzip magic bytes, and setting the decompression mode to `GUNZIP` or `INFLATE` according to the result. This enables gzip-only features like multi-member support to be used together with the `unzip*` autodetection support and thereby makes `gunzip*` and `unzip*` return identical results for gzip input again. Add a simple test for checking that features specific to `zlib.gunzip`, notably support for multiple members, also work when using `zlib.unzip`. PR-URL: https://github.com/nodejs/node/pull/5884 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-04-05src: replace ARRAY_SIZE with typesafe arraysizeBen Noordhuis
To prevent `ARRAY_SIZE(&arg)` (i.e., taking the array size of a pointer) from happening again. PR-URL: https://github.com/nodejs/node/pull/5969 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-03-31zlib: fix gzip member head/buffer boundary issueAnna Henningsen
Make sure that, even if an `inflate()` call only sees the first few bytes of a following gzip member, all members are decompressed and part of the full output. This change also modifies behaviour for trailing garbage: If there is trailing garbage which happens to start with the gzip magic bytes, it is no longer discarded but rather throws an error, since we cannot reliably tell random garbage from a valid gzip member anyway and have to try and decompress it. (Null byte padding is not affected, since it has been pointed out at various occasions that such padding is normal and discarded by `gzip(1)`, too.) Adds tests for the special case that the first `inflate()` call receives only the first few bytes of a second gzip member but not the whole header (or even just the magic bytes). PR-URL: https://github.com/nodejs/node/pull/5883 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-03-23zlib: Fix handling of gzip magic bytes mid-fileAnna Henningsen
Only treat the gzip magic bytes, when encountered within the file after reading a single block, as the start of a new member when the previous member has ended. Add test files that reliably reproduce #5852. The gzipped file in test/fixtures/pseudo-multimember-gzip.gz contains the gzip magic bytes exactly at the position that node encounters after having read a single block, leading it to believe that a new data member is starting. Fixes: https://github.com/nodejs/node/issues/5852 PR-URL: https://github.com/nodejs/node/pull/5863 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2016-03-15zlib: add support for concatenated membersKári Tristan Helgason
According to the spec gzipped archives can contain more than one compressed member. Previously Node's gzip implementation would only unzip the first member and throw away the rest of the compressed data. Issue #4306 is an example of this occurring in daily use. Fixes: https://github.com/nodejs/node/issues/4306 PR-URL: https://github.com/nodejs/node/pull/5120 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
2015-10-19zlib: decompression throw on truncated inputYuval Brik
Check for unexpected end-of-file error when decompressing. If the output buffer still has space after decompressing and deflate returned Z_OK or Z_BUF_ERROR - that means unexpected end-of-file. Added test-zlib-truncated.js for the case of truncated input. Fixed the zlib dictionary test to not end the inflate stream on a truncated output (no crc) of deflate Fixes: https://github.com/nodejs/node/issues/2043 PR-URL: https://github.com/nodejs/node/pull/2595 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2015-09-14src: use ZCtxt as a source for v8::IsolatesRoman Klauke
Other methods like `After` already use ZCtxt as the source for Enviroment/ v8::Isolate objects, this commit applies the same style to the other missing methods (`After sync` and `Write`) PR-URL: https://github.com/nodejs/node/pull/2547 Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-09-06src: replace usage of v8::Handle with v8::LocalMichaël Zasso
v8::Handle is deprecated: https://codereview.chromium.org/1224623004 PR-URL: https://github.com/nodejs/io.js/pull/2202 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-06-17async-wrap: add provider id and object info cbTrevor Norris
Re-add the wrapper class id to AsyncWrap instances so they can be tracked directly in a heapdump. Previously the class id was given without setting the heap dump wrapper class info provider. Causing a segfault when a heapdump was taken. This has been added, and the label_ set to the given provider name so each instance can be identified. The id will not be set of the passed object has no internal field count. As the class pointer cannot be retrieved from the object. In order to properly report the allocated size of each class, the new pure virtual method self_size() has been introduces. PR-URL: https://github.com/nodejs/io.js/pull/1896 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-05-18core: implement runtime flag to trace sync ioTrevor Norris
Use the --trace-sync-io flag to print a stack trace whenever a sync method is used after the first tick, excluding during the process exit event. (e.g. fs.readFileSync()) It does not track if the warning has occurred at a specific location in the past and so will print the warning every time. Reason for not printing during the first tick of the appication is so all necessary resources can be required. Also by excluding synchronous calls during exit is necessary in case any data needs to be logged out by the application before it shuts down. Fixes: https://github.com/nodejs/io.js/issues/1674 PR-URL: https://github.com/nodejs/io.js/pull/1707 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Petka Antonov <petka_antonov@hotmail.com>
2015-01-12Remove excessive copyright/license boilerplateisaacs
The copyright and license notice is already in the LICENSE file. There is no justifiable reason to also require that it be included in every file, since the individual files are not individually distributed except as part of the entire package.
2015-01-10zlib: do not unref() if wasn't ref()edFedor Indutny
In very unlikely case, where `deflateInit2()` may return error (right now happening only on exhausting all memory), the `ZCtx::Error()` will be called and will try to `Unref()` the handle. But the problem is that this handle was never `Ref()`ed, so it will trigger an assertion error and crash the program. Reviewed-by: Ben Noordhuis <info@bnoordhuis.nl> PR-URL: https://github.com/joyent/node/pull/8687 Cherry-picked-from: https://github.com/joyent/node/commit/8c868989be778246bc4b9558f087d0f93724b83d
2015-01-09src: zlib: revert concatenated-stream changesChris Dickinson
Revert "src: fix windows build error" and "zlib: support concatenated gzip files". This reverts commits be413ac732f59ffe621f264239e5e22b77d32025 and 1183ba47dfc2bc8b39f0c10d8dc9e9299a4470bf. Treating subsequent bytes as a concatenated zlib stream breaks npm install. Conflicts: test/parallel/test-zlib-from-multiple-gzip-with-garbage.js test/parallel/test-zlib-from-multiple-gzip.js test/parallel/test-zlib-from-multiple-huge-gzip.js Fixes: https://github.com/joyent/node/issues/8962 PR-URL: https://github.com/iojs/io.js/pull/240 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-07src: pass Isolate to additional locationsTrevor Norris
Due to a recent V8 upgrade, more methods require Isolate as an argument. PR-URL: https://github.com/iojs/io.js/pull/244 Reviewed-by: Ben Noordhuis <info@bnoordhuis.nl>
2014-11-11src: fix windows build errorBen Noordhuis
Fix a Windows-only build error that was introduced in commit 1183ba4 ("zlib: support concatenated gzip files"). Rename the NO_ERROR and FAILED enumerations, they conflict with macros of the same name in <winerror.h>. PR-URL: https://github.com/node-forward/node/pull/57 Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: Rod Vagg <rod@vagg.org>
2014-11-09zlib: support concatenated gzip filesLuis Reis
Reviewed-By: Fedor Indutny <fedor@indutny.com> PR-URL: https://github.com/joyent/node/pull/6442
2014-10-23src: mark more destructors with override keywordBen Noordhuis
The previous commits fixed oversights in destructors that should have been marked virtual but weren't. This commit marks destructors from derived classes with the override keyword.
2014-10-23src: replace NULL with nullptrBen Noordhuis
Now that we are building with C++11 features enabled, replace use of NULL with nullptr. The benefit of using nullptr is that it can never be confused for an integral type because it does not support implicit conversions to integral types except boolean - unlike NULL, which is defined as a literal `0`.
2014-10-13src: attach env directly to api functionsBen Noordhuis
Attach the per-context execution environment directly to API functions. Rationale: * Gets node one step closer to multi-isolate readiness. * Avoids multi-context confusion, e.g. when the caller and callee live in different contexts. * Avoids expensive calls to pthread_getspecific() on platforms where V8 does not know how to use the thread-local storage directly. (Linux, the BSDs.) PR-URL: https://github.com/node-forward/node/pull/18 Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-10-13src: remove unused Environment::GetCurrent() callsBen Noordhuis
Remove a few Environment::GetCurrent() calls that g++ failed to detect were not used for anything. The return value was assigned to a local variable but not used meaningfully. PR-URL: https://github.com/node-forward/node/pull/18 Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-10-12src: replace assert() with CHECK()Ben Noordhuis
Mechanically replace assert() statements with UNREACHABLE(), CHECK(), or CHECK_{EQ,NE,LT,GT,LE,GE}() statements. The exceptions are src/node.h and src/node_object_wrap.h because they are public headers. PR-URL: https://github.com/node-forward/node/pull/16 Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-10-12src: remove unnecessary HandleScopesBen Noordhuis
API callback functions don't need to create a v8::HandleScope instance because V8 already creates one in the JS->C++ adapter frame. PR-URL: https://github.com/node-forward/node/pull/16 Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-05-30src: replace CONTAINER_OF with type-safe functionBen Noordhuis
Replace the CONTAINER_OF macro with a template function that is as type-safe as a reinterpret_cast<> of an arbitrary pointer can be made. Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-04-02node: add signature to SET_PROTOTYPE_METHODC. Scott Ananian
This prevents segfaults when a native method is reassigned to a different object (which corrupts args.This()). When unwrapping, clients should use args.Holder() instead of args.This(). Closes #6690. Signed-off-by: Trevor Norris <trev.norris@gmail.com>
2014-03-16src: fix segfaults, fix 32 bits integer negationBen Noordhuis
Make calls to v8::Isolate::AdjustAmountOfExternalAllocatedMemory() take special care when negating 32 bits unsigned types like size_t. Before this commit, values were negated before they got promoted to 64 bits, meaning that on 32 bits architectures, a value like 42 got cast to 4294967254 instead of -42. That in turn made the garbage collector start scavenging like crazy because it thought the system was out of memory. That's bad enough but calls to AdjustAmountOfExternalAllocatedMemory() were made from weak callbacks, i.e. at a time when the garbage collector was already busy. It triggered asserts in debug builds and caused random crashes and memory corruption in release builds. The behavior in release builds is arguably a V8 bug and should perhaps be reported upstream. Partially fixes #7309 but requires further bug fixes to src/smalloc.cc that I'll address in a follow-up commit.
2014-03-13src: update to v8 3.24 APIsFedor Indutny
2014-02-22src: remove `node_isolate` from sourceFedor Indutny
fix #6899
2014-02-17Merge remote-tracking branch 'upstream/v0.10'Timothy J Fontaine
Conflicts: src/node_zlib.cc
2014-02-18zlib: introduce pending close stateFedor Indutny
zlib should not crash in `close()` if the write is still in progress. fix #7101
2014-02-08Merge remote-tracking branch 'upstream/v0.10'Timothy J Fontaine
Conflicts: deps/v8/src/preparser.cc deps/v8/src/win32-math.h doc/api/http.markdown src/node_buffer.h src/node_crypto.cc src/node_file.cc src/node_http_parser.cc
2014-02-08src: refactor buffer bounds checkingTimothy J Fontaine
Consolidate buffer bounds checking logic into Buffer namespace and use it consistently throughout the source.
2014-02-05async_wrap: add provider types/pass to constructorTrevor Norris
These will be used to allow users to filter for which types of calls they wish their callbacks to run. Signed-off-by: Timothy J Fontaine <tjfontaine@gmail.com>
2014-02-01zlib: add sync versions for convenience methodsNikolai Vavilov
2014-01-27node: register modules from DSO constructorsKeith M Wesolowski
Built-in modules should be automatically registered, replacing the static module list. Add-on modules should also be automatically registered via DSO constructors. This improves flexibility in adding built-in modules and is also a prerequisite to pure-C addon modules.