fs: validate position argument before length === 0 early return · nodejs/node@63c111c
@@ -646,6 +646,12 @@ function read(fd, buffer, offsetOrOptions, length, position, callback) {
646646647647length |= 0;
648648649+if (position == null) {
650+position = -1;
651+} else {
652+validatePosition(position, 'position', length);
653+}
654+649655if (length === 0) {
650656return process.nextTick(function tick() {
651657callback(null, 0, buffer);
@@ -659,12 +665,6 @@ function read(fd, buffer, offsetOrOptions, length, position, callback) {
659665660666validateOffsetLengthRead(offset, length, buffer.byteLength);
661667662-if (position == null) {
663-position = -1;
664-} else {
665-validatePosition(position, 'position', length);
666-}
667-668668function wrapper(err, bytesRead) {
669669// Retain a reference to buffer so that it can't be GC'ed too soon.
670670callback(err, bytesRead || 0, buffer);
@@ -717,6 +717,12 @@ function readSync(fd, buffer, offsetOrOptions, length, position) {
717717718718length |= 0;
719719720+if (position == null) {
721+position = -1;
722+} else {
723+validatePosition(position, 'position', length);
724+}
725+720726if (length === 0) {
721727return 0;
722728}
@@ -728,12 +734,6 @@ function readSync(fd, buffer, offsetOrOptions, length, position) {
728734729735validateOffsetLengthRead(offset, length, buffer.byteLength);
730736731-if (position == null) {
732-position = -1;
733-} else {
734-validatePosition(position, 'position', length);
735-}
736-737737return binding.read(fd, buffer, offset, length, position);
738738}
739739