Browse Source

Ext2FileSystem::readInode() should return an empty buffer for 0-length files.

Andreas Kling 6 years ago
parent
commit
750b27cb07
2 changed files with 4 additions and 0 deletions
  1. 1 0
      AK/ByteBuffer.h
  2. 3 0
      VirtualFileSystem/Ext2FileSystem.cpp

+ 1 - 0
AK/ByteBuffer.h

@@ -27,6 +27,7 @@ public:
         return *this;
         return *this;
     }
     }
 
 
+    static ByteBuffer createEmpty() { return ByteBuffer(Buffer<byte>::createUninitialized(0)); }
     static ByteBuffer createUninitialized(size_t size) { return ByteBuffer(Buffer<byte>::createUninitialized(size)); }
     static ByteBuffer createUninitialized(size_t size) { return ByteBuffer(Buffer<byte>::createUninitialized(size)); }
     static ByteBuffer copy(const byte* data, size_t size) { return ByteBuffer(Buffer<byte>::copy(data, size)); }
     static ByteBuffer copy(const byte* data, size_t size) { return ByteBuffer(Buffer<byte>::copy(data, size)); }
     static ByteBuffer wrap(byte* data, size_t size) { return ByteBuffer(Buffer<byte>::wrap(data, size)); }
     static ByteBuffer wrap(byte* data, size_t size) { return ByteBuffer(Buffer<byte>::wrap(data, size)); }

+ 3 - 0
VirtualFileSystem/Ext2FileSystem.cpp

@@ -260,6 +260,9 @@ ByteBuffer Ext2FileSystem::readInode(InodeIdentifier inode) const
         return nullptr;
         return nullptr;
     }
     }
 
 
+    if (e2inode->i_size == 0)
+        return ByteBuffer::createEmpty();
+
     // Symbolic links shorter than 60 characters are store inline inside the i_block array.
     // Symbolic links shorter than 60 characters are store inline inside the i_block array.
     // This avoids wasting an entire block on short links. (Most links are short.)
     // This avoids wasting an entire block on short links. (Most links are short.)
     static const unsigned maxInlineSymlinkLength = 60;
     static const unsigned maxInlineSymlinkLength = 60;