Commit graph

118 commits

Author SHA1 Message Date
Satoshi Tagomori
382645d440 namespace on read 2025-05-11 23:32:50 +09:00
David Rodriguez
281df1e495 [rubygems/rubygems] Remove Gem::Specification#mark_version
This gets in the middle if we ever start allowing to build as if using a
different RubyGems version than the one being run.

This could be useful to make `gem rebuild` a little more usable, and
it's already done by Bundler specs which already make this method a noop
when they need this.

I'm not sure forcefully setting this, even if user explicitly specified
something else is helpful.

Since this could potentially prevent gems explicitly setting a constant
RubyGems version from building, I changed the error of incorrect
RubyGems version from a hard error to a warning, since it will start
happening in those cases if we stop overwriting the version.

45676af80d
2024-05-03 15:12:55 +00:00
Samuel Giddins
d7ba0fec49 [rubygems/rubygems] Update lib/rubygems/package.rb
c4e75b9f74
2024-04-30 15:34:49 +00:00
Samuel Giddins
d950609ec7 [rubygems/rubygems] Add a limit to the size of the metadata and checksums files in a gem package.
This is to prevent a malicious gem from causing a denial of service by
including a very large metadata or checksums file,
which is then read into memory in its entirety just by opening the gem package.

This is guaranteed to limit the amount of memory needed, since
gzips (which use deflate streams for compression) have a maximum compression
ratio of 1032:1, so the uncompressed size of the metadata or checksums file
will be at most 1032 times the size of the (limited) amount of data read.

This prevents a gem from causing 500GB of memory to be allocated
to read a 500MB metadata file.

a596e3c5ec
2024-04-30 15:34:48 +00:00
David Rodríguez
53571de8e9 [rubygems/rubygems] Fix circular require warning
241d0aafcd
2024-04-29 09:04:33 +00:00
Jake Zimmerman
97b2cc3435 Allow FormatError to take either String or Gem for source
Most of the calls to `FormatError.new` pass `@gem` for the second argument, which has a `path` method.

But in one case—on package.rb:691 in `verify_gz`, the `source` argument is a `String`.

So if there's ever a GZip decode error when attempting to read the contents of the `data.tar.gz` file, instead of reporting the underlying GZip error (which might be something like "unexpected end of file"), we would report instead a NoMethodError coming from package.rb

```
Exception while verifying sorbet-0.5.11301.gem
ERROR:  While executing gem ... (NoMethodError)
    undefined method `path' for "data.tar.gz":String

        @path = source.path
                      ^^^^^
```

There are two ways to fix this:

1. Make `FormatError#initialize` aware of the fact that `source` might sometimes be a `String`
2. Make the call to `FormatError.new` in `verify_gz` pass `@gem` instead of `entry.full_name`.

I've chosen 1 because I think it's more useful to see "unexpected end of file in data.tar.gz" instead of "unexpected end of file in sorbet-0.5.11301.gem." The end of file **is actually** in data.tar.gz, not in the gem file itself, which was decoded successfully.
2024-03-28 15:54:33 +00:00
David Rodriguez
8ef923dc35 [rubygems/rubygems] Respect global umask when writing regular files
fd5cb7396f
2024-03-22 13:15:15 +00:00
Hiroshi SHIBATA
270ad76359
Revert "Ensure File.open applies default umask on gem extract"
This reverts commit 01f9766aa0.
2024-01-24 14:10:05 +09:00
Martin Emde
01f9766aa0 Ensure File.open applies default umask on gem extract 2024-01-24 13:50:16 +09:00
Hiroshi SHIBATA
82496f2b38 Merge RubyGems-3.5.2 and Bundler-2.5.2 2023-12-22 07:24:04 +09:00
Samuel Giddins
505715ddf1 [rubygems/rubygems] Fewer allocations in gem installation
For now, on a small rails app I have hanging around:

```
==> memprof.after.txt <==
Total allocated: 872.51 MB (465330 objects)
Total retained:  40.48 kB (326 objects)

==> memprof.before.txt <==
Total allocated: 890.79 MB (1494026 objects)
Total retained:  40.40 kB (328 objects)
```

Not a huge difference in memory usage, but it's a drastic improvement
in total number of allocations.

Additionally, this will pay huge dividends once
https://github.com/ruby/zlib/pull/61 is merged, as it will allow us to
completely avoid allocations in the repeated calls to readpartial,
which currently accounts for most of the memory usage shown above.

f78d45d927
2023-12-11 23:14:58 +00:00
David Rodríguez
2755cb1b2f [rubygems/rubygems] Use modern hashes consistently
bb66253f2c
2023-12-07 22:29:33 +00:00
David Rodríguez
54511303a4 [rubygems/rubygems] Drop support for Ruby 2.6 and Ruby 2.7 in RubyGems
10c26a483d
2023-11-13 11:06:10 +09:00
negi0109
203fdd738b [rubygems/rubygems] Fixed include realpath in error statement
ac3b85bd5e
2023-09-11 21:06:22 +00:00
negi0109
8bb61077ad [rubygems/rubygems] Fixed false positive SymlinkError in symbolic link directory
58173ff2ea
2023-09-11 21:06:21 +00:00
Martin Emde
e913431687 [rubygems/rubygems] Raise Gem::Package::FormatError on EOF, indicating corrupt gem
Gem::Package::TarReader::Entry now raises EOFError or returns nil
appropriately based on Ruby core IO.read and IO.readpartial behavior.

Zlib will respond accordingly by raising Zlib::GzipFile::Error on EOF.

When verifying a gem or extracting contents, raise FormatError similar
to other cases of corrupt gems.

Addresses a bug where Gem::Package would attempt to call size on nil
instead of raising a more descriptive and useful error, leading users
to assume the problem is internal to rubygems.

Remove unused error class TarReader::UnexpectedEOF that was never raised
since the NoMethodError on nil would happen first. Use EOFError instead.

dc6129644b
2023-08-17 23:16:57 +00:00
Hiroshi SHIBATA
827d66266b [rubygems/rubygems] auto-correct Style/YodaCondition
6d9e8025dc
2023-06-15 07:01:28 +09:00
Hiroshi SHIBATA
d89cc317c6
util/rubocop -A --only Style/NumericLiteralPrefix 2023-04-11 19:12:28 +09:00
Hiroshi SHIBATA
250e97c0fb [rubygems/rubygems] util/rubocop -A --only Style/FormatString
132a56569d
2023-04-07 05:13:05 +00:00
Hiroshi SHIBATA
acf12b6dfd util/rubocop -A --only Style/AsciiComments 2023-03-23 17:18:49 +09:00
Hiroshi SHIBATA
f24a86d83f util/rubocop -A --only Layout/EmptyLineAfterMagicComment 2023-03-23 17:18:49 +09:00
Hiroshi SHIBATA
50a03035ee util/rubocop -A --only Lint/NonLocalExitFromIterator 2023-03-23 17:18:49 +09:00
Hiroshi SHIBATA
2e3cd1dc3e [rubygems/rubygems] Enabled Style/RedundantReturn cop
05cc97bdf8
2023-03-23 17:18:49 +09:00
Hiroshi SHIBATA
5211900d37 util/rubocop -A --only Style/SymbolProc 2023-03-17 18:50:55 +09:00
Hiroshi SHIBATA
6ad269dc39 [rubygems/rubygems] util/rubocop -A --only Style/RescueStandardError
80b57da926
2023-03-17 18:50:55 +09:00
Hiroshi SHIBATA
3fe5909ef1 [rubygems/rubygems] util/rubocop -A --only Style/SelfAssignment
7c1168c623
2023-03-17 18:50:55 +09:00
Hiroshi SHIBATA
d2cebb4e31 [rubygems/rubygems] util/rubocop -A --only Style/NumericLiterals
860669b08a
2023-03-17 18:50:55 +09:00
Hiroshi SHIBATA
4bb5ce8188 [rubygems/rubygems] util/rubocop -A --only Style/StringLiteralsInInterpolation
cb554f6eb7
2023-03-17 18:50:55 +09:00
Hiroshi SHIBATA
ce21ce6f23 [rubygems/rubygems] util/rubocop -A --only Layout/FirstArgumentIndentation
0542726fd3
2023-03-17 18:50:55 +09:00
Hiroshi SHIBATA
05208c3875 [rubygems/rubygems] util/rubocop -A --only Lint/UnusedBlockArgument
d8efd919db
2023-03-17 18:50:55 +09:00
Hiroshi SHIBATA
b7ad60a794 Merge RubyGems/Bundler master
from 72fd3dd209
2022-12-26 15:09:21 +09:00
Kevin Newton
68a5b0f086 [rubygems/rubygems] Mask the file mode when extracting files
When extracting files from the tarball, a mode is retrieved from
the header. Occasionally you'll encounter a gem that was packaged
on a system whose permission bits result in a value that is larger
than the value that File.chmod will allow (anything >= 2^16). In
that case the extraction fails with a RangeError, which is pretty
esoteric.

If you extract the tarball with the tar and gunzip utilities, the
file permissions end up being just the bottom 16 bits masked off
from the original value. I've mirrored that behavior here. Per the
tar spec:

> Modes which are not supported by the operating system restoring
> files from the archive will be ignored.

I think that basically means what I've done here.

---

This commit also changes the behavior very slightly with regard to
when the chmod is called. Previously it was called while the file
descriptor was still open, but after the write call.

When write flushes, the file permissions are changed to the mode
value from the File.open call, undoing the changes made by
FileUtils.chmod. CRuby appears to flush the buffer after the
chmod call, whereas TruffleRuby flushes before the chmod call.
So the file permissions can change depending on implementation.
Both implementations end up getting the correct file permissions
for the bottom 9 bits (user, group, world), but differ with
regard to the sticky bit in the next 3.

To get consistent behavior, this commit changes it to close the
file descriptor before attempting to chmod anything, which makes
it consistent because the write flushes in both cases.

22ce076e99
2022-09-15 14:49:20 +09:00
Hiroshi SHIBATA
44264b4fee Merge rubygems/bundler HEAD.
Pick from dfbb5a3811
2022-08-09 12:05:19 +09:00
David Rodríguez
542040fb83 [rubygems/rubygems] Warn dangling symlinks
425b78637f
2022-08-04 13:36:45 +09:00
David Rodríguez
0591780a74 [rubygems/rubygems] Extract entry.full_name to a variable
3973773005
2022-08-04 13:36:44 +09:00
Takuya Noguchi
d7ffd3fea4
RubyGems: Enable Style/StringLiterals cop
Signed-off-by: Takuya Noguchi <takninnovationresearch@gmail.com>
2022-07-22 12:07:23 +09:00
Nobuyoshi Nakada
b85457c710 [rubygems/rubygems] [DOC] Enable Gem::Package example
Other code must not be between the doc and class definition.

366784aae5
2022-03-15 08:40:35 +09:00
Hiroshi SHIBATA
d22511fd75 Merge rubygems/rubygems HEAD.
Picked at 12aeef6ba9a3be0022be9934c1a3e4c46a03ed3a
2022-01-19 15:01:44 +09:00
David Rodríguez
f04954d95c
[rubygems/rubygems] Normalize end alignment style with Bundler
f7f504b24c
2022-01-19 11:20:36 +09:00
David Rodríguez
6c39a272af [ruby/rubygems] We no longer need to check realpaths
Since symlinks and absolute paths are already checked.

de19bc4c7e
2021-10-10 23:12:57 +09:00
David Rodríguez
bbcf8f87ac [ruby/rubygems] Check safety of packaged symlinks
If we explicitly disallow the creation of symlinks that point to files
outside of the destination directory, we can avoid any other safety
checks while creating directories, because we can be sure they will
always fall under the destination directory as well.

555692b8de
2021-10-10 23:12:47 +09:00
David Rodríguez
a5289bfa71 [ruby/rubygems] Install location safety should consider casing
0a0ad34af3
2021-10-10 23:12:38 +09:00
David Rodríguez
6c878731c1 [ruby/rubygems] Remove redundant File.expand_path
`File.realpath` already expands paths.

25524ebbeb
2021-10-10 23:12:28 +09:00
David Rodríguez
59c24f054e [ruby/rubygems] Simplify File.expand_path usage
02e3cf44bf
2021-10-10 23:12:10 +09:00
David Rodríguez
11720818f6 [ruby/rubygems] Don't make duplicated checks on directory safety
This seems to speed up `gem install` on Windows by more than 50%.

1970b1296d
2021-10-10 23:12:03 +09:00
David Rodríguez
54ae3f587e [rubygems/rubygems] Prefer require_relative to require for internal requires
c74fc58695
2021-08-31 19:06:14 +09:00
Hiroshi SHIBATA
96741765d8 Merge the master branch of RubyGems 2021-04-15 15:36:15 +09:00
Hiroshi SHIBATA
4aca77edde Merge prepare version of RubyGems 3.2.0 2020-12-08 17:30:02 +09:00
Hiroshi SHIBATA
b717f73402
Revert "Manually merged from https://github.com/rubygems/rubygems/pull/2636"
31a6eaabc1 is obsoleted with
  https://github.com/rubygems/rubygems/pull/3820
2020-09-23 22:01:44 +09:00
Hiroshi SHIBATA
31a6eaabc1
Manually merged from https://github.com/rubygems/rubygems/pull/2636
Enable Style/EmptyLinesAroundClassBody rubocop cop.
2020-09-23 21:02:56 +09:00